[concurrency-interest] Soliciting input about removeAllThreadLocals
Sun, 8 Dec 2002 13:39:44 -0500
On Sunday 08 December 2002 12:54 pm, Luke Blanshard wrote:
> Many years ago, when I was a young programmer, an older and wiser man
> explained one of the most important precepts of good programming to me
> thus: Global Variables Are Bad.
> In fact, thread-local variables are worse than global variables in at
> least one respect, for exactly the issue you raise here: the same thread
> might well be used for more than one purpose.
ThreadLocals do not have to be global; you can as well have thread locals that
are instance fields (strictly speaking, it actually _narrows_ the scope). I
use a construct like that to serialize asynchronous remote invocations that
are performed on the same remote stub from the same thread. Like most things
in computer programming, thread locals are useful or even irreplaceable in
some situations, but they may hurt you if you are using them wherever you
should be using something else.