I'm using ThreadLocal
variables (through Clojure's vars, but the following is the same for plain ThreadLocal
s in Java) and very often run into the issue that I can't be sure that a certain code path will be taken on the same thread or on another thread. For code under my control this is obviously not too big a problem, but for polymorphic third party code there's sometimes not even a way to statically determine whether it's safe to assume single threaded execution.
I tend to think this is a inherent issue with ThreadLocal
s, but I'd like to hear some advise on how to use them in a safe way.