-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pavan,

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
simultaneously).

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG+6ya9CaO5/Lv0PARAgTKAKC4UFTpSjZm65Kuv9390onquuZQWACgt2Sw
L6jIt3B3woKIxvM/jVSPs+4=
=4Ge9
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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