Hi,

I've got some questions regards the use of ThreadLocals in context listeners:
(This is a general question, but I tested this with tomcat 6.0.32 only)

1. It's unspecified in the servlet spec 2.5 if a servlet context listener is allowed to take the use of ThreadLocals during contextInitialized().
   Is this (also) allowed in tomcat?


   If the answer of this question is "yes":

2. Tomcat invokes the contextInitialized() method with the main thread.
At some later time, the main thread (most probably) spawns some more threads (e.g. the http connector/acceptor threads). Because ThreadLocals are inherited from its parent threads, the thread local value references of each ThreadLocal object
   are copied to the child threads.

With the result that even if the reference to the original ThreadLocal instance is removed (for example during contextDestroyed(), the inherited ThreadLocals are still there and reference to the original values - and will most probably remain in the spawned threads forever. (I am aware that tomcat's leak-prevention system / WebClassLoader.clearThreadLocalMap() may remove them, but I can neither rely on that at customer installations nor consider this as a good style)

a) Is the main thread usage for context initializers intended? Is this configurable? b) What's the best way to deal with this situation (especially if the avoidance of ThreadLocals in context initializers is not an option)? c) Wouldn't it be better to create an individual thread for (each) context initializer to avoid these kind of problems?


Thanks you very much in advance.

- Patric
















---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to