tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Simultaneous Requests to servlet
Date Thu, 27 Sep 2007 13:14:02 GMT
Hash: SHA1


Pavan Singaraju wrote:
>     I have a basic question about servlets in Tomcat 5.0.18. In theory, when
> there are simultaneous requests come for a servlet, it will either queue the
> requests and serve one by one or create multiple threads of the servlet and
> serve the request.

Nope: all requests will be handled in parallel unless other factors
exist (such as more requests than your server is configured to accept

There used to be a SingleThreadModel interface you could implement that
would force the behavior you describe but it has been deprecated.

>     My question is, what / how tomcat handles this situation?

Tomcat does not take any special action when multiple requests come in
for a particular servlet.

> I need the answer for this, because, i have a synchronized access to an
> object from the servlet, and if tomcat handles the monitor for the object
> then i don't need to handle the monitoring condition else i may have to do
> it.

Tomcat will never handle monitors for your synchronized objects: the JVM
will do it. If you need serialized access to an object, then you need to
synchronize it yourself. Better yet, make multiple copies of it so you
don't have to serialize access to it (them). Even better, fix your
design so that it's thread safe and you don't need any synchronization
at all.

> I understand that Tomcat has a SingleThreadModel interface that allows
> only one thread access/One request at a time model.

SingleThreadModel has been deprecated as of Servlet API v2.4. Don't use it.

> But help me solve the previous problem.

You can alway do this:

private Whatever _myProtectedResource;

public void service(HttpServletRequest req, HttpServletResponse rsp)
    synchronized (_myProtectedResource) {
        // do whatever you need to do in here that requires exclusive
        // access to _myProtectedResource

Hope that helps,
- -chris
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message