public class ThreadLocal<T> extends Object
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.Thread
Constructor and Description |
---|
ThreadLocal()
Creates a new thread-local variable.
|
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the value of this variable for the current thread.
|
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.
|
public T get()
initialValue()
.protected T initialValue()
null
.public void set(T value)
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.public void remove()
get()
before a set(T)
,
#get()
will call initialValue()
and create a new
entry with the resulting value.