java.lang.Object | |
↳ | java.lang.ThreadLocal<T> |
Known Direct Subclasses |
Implements a thread-local storage, that is, a variable for which each thread
has its own value. All threads share the same
ThreadLocal
object,
but each sees a different value when accessing it, and changes made by one
thread do not affect the other threads. The implementation supports
null
values.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Creates a new thread-local variable.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Returns the value of this variable for the current thread.
|
||||||||||
|
Removes the entry for this variable in the current thread.
|
||||||||||
|
Sets the value of this variable for the current thread.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Provides the initial value of this variable for the current thread.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
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()
.
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.
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.
value | the new value of the variable for the caller thread. |
---|
Provides the initial value of this variable for the current thread.
The default implementation returns
null
.