[concurrency-interest] Soliciting input about removeAllThreadLocals

Joshua Bloch joshua.bloch@sun.com
Sun, 08 Dec 2002 22:11:02 -0800


David,

>I think this gets to the crux of the matter: thread-local versus
>task-local. I can not imagine (other than for introspection/debugging
>purposes) a thread-local variable the value of which is *entirely*
>independent of the task being executed by the thread, and which it
>would thus be wrong to reset when commencing to execute a new task.
>
   I can.  Keep in mind that the abstractions may be completely 
unrelated.  Someone writes a little facility that uses ThreadLocal for 
some reason or other with no thought to tasks.  Then it gets called from 
a task.

>I can easily imagine usage of thread-locals in a way that are really
>task-local and thus it would be wrong not to reset them when a new
>task commences.
>
In this sort of use, the ThreadLocal is generally updated manually in a 
finally block so there's no need ot reset.

>...
>
>And probably there are other distinctions that could be made.
>
   I actually wrote a piece taxonomizing the uses of ThreadLocal many 
years ago when I campaigned to put them in the libraries.  I'll try to 
dig it up.  I think it would be more than a little bit entertaining to 
look at resets in the context of each usage.

         Regards,

         Josh