> From: lightbulb432 [mailto:[EMAIL PROTECTED] > 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]