[concurrency-interest] reusing threads and thread local state

Mike Skells mike.skells at ebizz-consulting.com
Wed May 4 15:19:18 EDT 2005

> Larry Riedel wrote:
> I don't use threadlocals myself because it is just as easy to use a
> Hashtable<Thread,Hashtable<String,?>> via a static factory which I can 
> control access to and manage clearing etc on my own.

[Mike Skells] 
Interesting to know how you manage the cleanup, as you now have a strong
reference to a Thread in you HashMap, so the Thread cannot be GC until every
one of your explicit cleanups completes

Also all of the ThreadLocals that are created in that thread are not GCed
either (fixed in JDK1.5).

If this is run in an environment that manages Threads (outside you control)
such as an appserver then the cleanup is complicated further.  

Looks to me as if you have created your own personal memory leak!


Should the ThreadLocals be cleared from the Thread when the Thread completes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 1906 bytes
Desc: not available
Url : /pipermail/attachments/20050504/47267b18/winmail.bin

More information about the Concurrency-interest mailing list