> From: Patric Rufflar [mailto:pat...@rufflar.com] > Subject: RE: ThreadLocals, context listeners and classloader leaks
> 1. contextInitializer() sets value A to the ThreadLocal X > in thread main > 2. childs threads get spawned from main thread, now we have > more than one ThreadLocal which references to value A No; again, a ThreadLocal is _not_ inherited, but an InheritableThreadLocal is. These are different animals. > 3. Reference to ThreadLocal X gets dropped, but references > to value A still exist - without being able to remove them. Why can't they be removed? (The code to do so is ugly, but readily findable with Google.) > But wouldn't it be much easier for everyone if tomcat would > always use a separate thread for each context initializer Again, that would fix _one_ stupid programmer trick, out of the uncountable number of potential errors. Note that Tomcat 7 includes a ThreadLocalLeakPreventionListener, but it is only invoked during undeployment of a <Context> to clean up <Executor> thread pools. It would certainly be possible to use this logic upon return from an initializer; filing a bugzilla enhancement request would at least allow some discussion by the committers. - 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.