Build 1.0_r1(from source)

java.lang
Class ThreadLocal<T>

java.lang.Object
  extended by java.lang.ThreadLocal<T>
Direct Known Subclasses:
InheritableThreadLocal

public class ThreadLocal<T>
extends Object

A variable for which each thread has its own value. Supports null values.

See Also:
Thread

Nested Class Summary
(package private) static class ThreadLocal.Values
          Per-thread map of ThreadLocal instances to values.
 
Constructor Summary
ThreadLocal()
          Creates a new thread local variable.
 
Method Summary
 T get()
          Returns the value of this variable for the current thread.
(package private)  ThreadLocal.Values initializeValues(Thread current)
          Creates Values instance for this thread and variable type.
protected  T initialValue()
          Provides the initial value of this variable for the current thread.
 void remove()
          Removes the entry for this variable in the current thread.
 void set(T value)
          Sets the value of this variable for the current thread.
(package private)  ThreadLocal.Values values(Thread current)
          Gets Values instance for this thread and variable type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadLocal

public ThreadLocal()
Creates a new thread local variable.

Method Detail

get

public T get()
Returns the value of this variable for the current thread. If an entry doesn't yet exist for this variable on this thread, this method will create an entry, populating the value with the result of initialValue().


initialValue

protected T initialValue()
Provides the initial value of this variable for the current thread. The default implementation returns null.


set

public void set(T value)
Sets the value of this variable for the current thread. If set to null, the value will be set to null and the underlying entry will still be present.


remove

public void remove()
Removes the entry for this variable in the current thread. If this call is followed by a get() before a #set(T), #get() will call initialValue() and create a new entry with the resulting value.


initializeValues

ThreadLocal.Values initializeValues(Thread current)
Creates Values instance for this thread and variable type.


values

ThreadLocal.Values values(Thread current)
Gets Values instance for this thread and variable type.


Build 1.0_r1(from source)

Please submit a feedback, bug or feature