ThreadLocal - II
20 August 2008Continuing from the previous example, do note that each thread will hold an implicit reference to its copy of a thread-local variable. It will keep holding as long as the thread is alive and the ThreadLocal instance is accessible; When a thread is killed, all of its copies of thread-local instances are subject to garbage collection.
Methods provided by this class:
Object get() protected Object initialValue() void set(Object value)
Use get() to get the value in the current thread’s copy of this thread-local variable.
Use set(…) to set the current thread’s copy of this thread-local variable to the specified value.
initialValue() simply returns the current thread’s initial value for this thread-local variable.
I hope you will use this in your code where needed and will find this really useful.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: ThreadLocal - II