[concurrency-interest] reusing threads and thread local state

David Holmes dholmes at dltech.com.au
Sat Apr 30 17:48:20 EDT 2005

Larry Riedel writes:
> I think when policy dictates, method(s) providing
> mechanisms for accessing ThreadLocals in this manner
> should of course support the throwing of appropriate
> exceptions such as IllegalAccessException.

Other than breaking encapsulation what purpose would having such an
iteration method serve? If you can't fully violate encapsulation by
accessing in-accessible fields then you can't clear them. If you can't clear
them all then there is no point trying to do anything this way.

ThreadLocals are an implementation detail, not something that a thread
should need to concern themselves about. The problems stem from mis-use of
ThreadLocals by libraries, or by those libraries not providing suitable
API's for clearing them.

I'd rather see and discuss specific examples of where there is a need to
clear ThreadLocal's than to entertain an API that exposes them all and
encourages further misuse.

David Holmes

More information about the Concurrency-interest mailing list