tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caldarale, Charles R" <Chuck.Caldar...@unisys.com>
Subject RE: Is ThreadLocal safe to use in servlets
Date Sat, 23 Jun 2007 20:34:03 GMT
> From: lightbulb432 [mailto:veerukrishnan@hotmail.com] 
> Subject: Re: Is ThreadLocal safe to use in servlets
> 
> A different way of asking this question is where/when
> does Tomcat start the Thread that handles a given
> request, and what is executed in the context of that
> thread? (e.g. filters, listeners, other things, servlets 
> of course)

Tomcat utilizes a thread pool for processing requests; the same thread
is used for the duration of the request through the entire
filter/servlet chain (required by the servlet spec), including data base
and other external resource access.  However, since the threads are
pooled, you can't count on ever seeing the same thread twice in a given
servlet, so ThreadLocal objects are best created and destroyed during
individual request handling; trying to keep them around longer runs the
risk of their continuing to exist even after a webapp has been stopped
or undeployed, resulting in garbage collection problems.

Since Listeners are not associated with a specific request, there's no
guarantee that the thread running through any Listener code will ever be
used for a request for the associated webapp, and there's no guarantee
it won't.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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


Mime
View raw message