[concurrency-interest] Bug in ThreadLocal ?

Hanson Char hanson.char at gmail.com
Fri Apr 13 14:02:23 EDT 2007


According to the javadoc of ThreadLocal#remove (in jdk1.6),

    "If this thread-local variable is subsequently read by the current
thread, its value will be reinitialized by invoking its initialValue method"

So I would expect, within the same thread, a ThreadLocal#get followed
by ThreadLocal#remove
followed by ThreadLocal#get would result in ThreadLocal#initialValue being
invoked twice.

But this is not the case.  The last "get" did not cause the "initValue" to
be invoked.  When I looked at the code of the "remove" and "get" method
implementation, it seems there is a bug in that the internal "t.threadLocals"
should be set to null when the remove method is invoked, but is not
currently the case.

Am I mistaken or is this a bug ?  Comment ?

Hanson Char
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070413/d1b9ed03/attachment.html 

More information about the Concurrency-interest mailing list