ThreadLocal - II

20 August 2008

Continuing 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.

del.icio.us:ThreadLocal - II  digg:ThreadLocal - II  spurl:ThreadLocal - II  wists:ThreadLocal - II  simpy:ThreadLocal - II  newsvine:ThreadLocal - II  blinklist:ThreadLocal - II  furl:ThreadLocal - II  reddit:ThreadLocal - II  fark:ThreadLocal - II  blogmarks:ThreadLocal - II  Y!:ThreadLocal - II  smarking:ThreadLocal - II  magnolia:ThreadLocal - II  segnalo:ThreadLocal - II  gifttagging:ThreadLocal - II

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

Leave a Reply