tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Threads Question in Tomcat
Date Tue, 27 Aug 2002 17:15:24 GMT
Hi,
Keep in mind that tomcat is a reference implementation of the servlet
spec.  I don't remember the servlet spec answering these questions, so
tomcat isn't obliged to implement things any one way.

>1. Is it true that requests from the SAME client
>always served by the SAME thread?

Not always.  Even if a servlet implements SingleThreadModel, the
container may still keep a pool of instances of this servlet and issue
requests as they come in, as long as no two requests share an instance
at the same time (i.e. they'll process one at a time).

>2. What if the SAME client access 2 different servlets
>in a servlet container? Is it still served by the SAME
>thread?

Not always.  

>3. What happens if the client send another request
>BEFORE the first request finished execution? Will the
>second request queue up somewhere in servlet
>container? Or it will be served by a different thread?

If there's something that can handle this request, it will be handled
independent of the first request.  So it could get handled before the
1st request is done executing.

>4. Is it recommend to use ThreadLocal when I write
>Servlet code?

Be very careful with ThreadLocal fields.  I've seen a couple of very
difficult to debug issues with using ThreadLocal.  Whether you decide to
use ThreadLocal in your design or not should not have to do with tomcat,
as your code should be to the servlet spec as far as tomcat is
concerned, and not to tomcat's particular implementation of things like
the single thread model. This way you will be assured of
container-independence should you need to change containers.

Yoav Shapira
Millennium ChemInformatics


Mime
View raw message