Dikan Xing wrote:
When two (almost) concurrent requests to the SAME servlet occurs (for example,I 
type the same url in two individual browser window), I find that Tomcat seems 
not to work on the second request until the first is done.

Are the two browser windows truly individual, or could they be part of the same
browser process? It seems that browsers may constrain themselves in several ways
when accessing a single resource (server, URL).

However, in my situtaion, my servlet should wait for some other resources to 
respond. Those resources are quick-responded, but transimssion of requests to & 
responses from those resources cost much time. Therefore, if the servlet could be 
run (service method be called) immediately instead of the previous is done, the 
total response time could be reduced.

Then you should, as Christopher mentioned, check that the contention is not 
caused
by those other resources (either via some pooling/synchronization  mechanism 
within
your app only letting one request at a time to touch the external resource, or
somehow the external resource itself being able to only service a single request
at a given time).

Is there any option in Tomcat so that I can configurate it to call the same 
servlet service method (doGet, doPost) simultanously instead of one by one?

No options needed -- not even if you're using SingleThreadModel in your servlet.

I just wrote a small test and ran it in Tomcat 6.0.14 (not current, but that's
what I happened to have at hand);

I wrote two servlets, with request body essentially "Thread.sleep(5000)", 
followed
by a printout identifying the servlet (class and instance). One of the servlets
was a regular servlet, another was a servlet implementing SingleThreadModel.

Then I wrote a test program; a Java command-line application to spawn five 
threads
for making requests to the regular servlet (MTServlet, as in multi-threaded), 
and
another five threads for making requests to the servlet implementing 
SingleThreadModel
(STServlet).

Below is output from a run of the test program against a server hosting these 
two
servlets:

Start: Tue Apr 22 21:56:28 EEST 2008
Hello from STServlet instance 3
Hello from MTServlet instance 1
Hello from MTServlet instance 1
Hello from STServlet instance 2
Hello from MTServlet instance 1
Hello from MTServlet instance 1
Hello from MTServlet instance 1
Hello from STServlet instance 5
Hello from STServlet instance 4
Hello from STServlet instance 6
Stop: Tue Apr 22 21:56:34 EEST 2008

So, all servlets finished within six seconds of starting the first one -- even 
those
implementing the SingleThreadModel. It should also be noted that all MTServlet 
calls
are handled by a single MTServlet instance (in parallel), but with STServlet the
parallelism comes from Tomcat creating several instances of the servlet (as 
allowed
by the Servlet Specification for servlets implementing the SingleThreadModel).

I've seen something like you describe, and it was when someone had either 
declared
the doGet() method (or another method called within doGet()) as synchronized, or
had written a synchronized code block referring to some single object for all 
requests.

--
..Juha

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to