Does Java CGI Require Thread Management

J

JR

Hi. I have about about two dozens CGI scripts written in Perl that I
need to convert to Java. The machine on which these scripts reside
doesn't support servlets, so I'm stuck with converting basic CGI from
one language to another. With any CGI, regardless of language, is it
necessary to manage threads, or is that taken care of by the server
handling the request? My limited understanding is that a CGI request
will spawn a new process, and create a unique thread for that process.

Also, I'd like one day to be able to move the Java CGI programs that I
will write as part of the above conversion to a machine that does
support servlets. I'd appreciate any recommendations as to references
that clearly explain how to handle the multi-threaded capability of
servlets. My only experience with threads so far is work from a
chapter of Ivor Horton's Beginning Java 2. The concepts seem pretty
difficult to grasp, and I'm not sure how I could apply them to an a
servlet that may have from x to y number of possible threads. It
would be awesome if there were a thread manager class that handled
threads for the programmer, but I'm probably missing the point of
threads to hope for that.

Thanks.

JR
 
M

Michael Borgwardt

JR said:
Hi. I have about about two dozens CGI scripts written in Perl that I
need to convert to Java. The machine on which these scripts reside
doesn't support servlets, so I'm stuck with converting basic CGI from
one language to another. With any CGI, regardless of language, is it
necessary to manage threads, or is that taken care of by the server
handling the request? My limited understanding is that a CGI request
will spawn a new process, and create a unique thread for that process.

This is indeed the case, and the reason why you will experience HORRIBLE
performace if you use Java like that. Your server would have to start a
separate JVM process for each request, and starting up a JVM takes much
more time and memory than the perl interpreter.

My advice: stick with Perl until you can run servlets.

Also, I'd like one day to be able to move the Java CGI programs that I
will write as part of the above conversion to a machine that does
support servlets. I'd appreciate any recommendations as to references
that clearly explain how to handle the multi-threaded capability of
servlets. My only experience with threads so far is work from a
chapter of Ivor Horton's Beginning Java 2. The concepts seem pretty
chapter of Ivor Horton's Beginning Java 2. The concepts seem pretty
difficult to grasp, and I'm not sure how I could apply them to an a
servlet that may have from x to y number of possible threads. It
would be awesome if there were a thread manager class that handled
threads for the programmer, but I'm probably missing the point of
threads to hope for that.

Actually, the only thing you need to know about threads when
programming servlets is: don't use them. The servlet container
will act sort of like your "thread manager", i.e. it will
automatically run each request in a separate thread(possibly
using a pool).
 
D

Dave Glasser

(e-mail address removed) (JR) wrote on 9 Nov 2004 08:42:10 -0800 in
comp.lang.java.programmer:
Hi. I have about about two dozens CGI scripts written in Perl that I
need to convert to Java. The machine on which these scripts reside
doesn't support servlets, so I'm stuck with converting basic CGI from
one language to another.

I'm curious, how could a machine support a JVM but not servlets?
Tomcat is free and fairly lightweight. If your machine can support
running Java programs as CGI processes, which would entail multiple
concurrent running JVMs on a busy server, it should handle Tomcat
without a problem.

With any CGI, regardless of language, is it
necessary to manage threads, or is that taken care of by the server
handling the request? My limited understanding is that a CGI request
will spawn a new process, and create a unique thread for that process.

That's right.
Also, I'd like one day to be able to move the Java CGI programs that I
will write as part of the above conversion to a machine that does
support servlets. I'd appreciate any recommendations as to references
that clearly explain how to handle the multi-threaded capability of
servlets. My only experience with threads so far is work from a
chapter of Ivor Horton's Beginning Java 2. The concepts seem pretty
difficult to grasp, and I'm not sure how I could apply them to an a
servlet that may have from x to y number of possible threads. It
would be awesome if there were a thread manager class that handled
threads for the programmer, but I'm probably missing the point of
threads to hope for that.

The main thing you'd have to do would be to avoid using instance
variables in a servlet or JSP, since other threads (simultaneous
requests to the same servlet or JSP) would be able to change their
value. Use local variables to reference data that can change during
the course of a request.



--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top