I’m declaring a ThreadLocal object and setting a value like below. Is there anyway to reference this numberThreaLocalObj variable outside of this class within the same thread? I’ve found some code the seems to clear ALL the threadlocals, but I just need to clear this particular Threadlocal variable based on a condition. Unfortunately this is a inherited technical design. EDIT
Tag: thread-local
Is it a bad practice to use a ThreadLocal Object for storing web request metadata?
I am working on a j2ee webapp divided in several modules. I have some metadata such as user name and preferences that I would like to access from everywhere in the app, and maybe also gather data similar to logging information but specific to a request and store it in those metadata so that I could optionally send it back
How to clean up ThreadLocals
Does any one have an example how to do this? Are they handled by the garbage collector? I’m using Tomcat 6. Answer The javadoc says this: “Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its
Performance of ThreadLocal variable
How much is read from ThreadLocal variable slower than from regular field? More concretely is simple object creation faster or slower than access to ThreadLocal variable? I assume that it is fast enough so that having ThreadLocal<MessageDigest> instance is much faster then creating instance of MessageDigest every time. But does that also apply for byte[10] or byte[1000] for example? Edit: