java.lang.ThreadLocal<T>
A variable for which each thread has its own value. Supports null
values.
Known Direct Subclasses
InheritableThreadLocal<T> |
A variable for which each thread has its own value; child threads will
inherit the value at thread creation time. |
Summary
Public Constructors
Public Methods
Protected Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
ThreadLocal()
Creates a new thread local variable.
Public Methods
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().
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.
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.
Protected Methods
protected
T
initialValue()
Provides the initial value of this variable for the current thread.
The default implementation returns null
.