Known Direct Subclasses
|
Class Overview
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.
Summary
Public Constructors |
|
ThreadLocal()
Creates a new thread-local variable.
|
Public Methods |
T
|
get()
Returns the 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.
|
Protected Methods |
T
|
initialValue()
Provides the initial value of this variable for the current thread.
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
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()
.
Returns
- the current value of the variable for the calling thread.
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.
Parameters
value
| the new value of the variable for the caller thread.
|
Protected Methods
protected
T
initialValue
()
Provides the initial value of this variable for the current thread.
The default implementation returns null
.
Returns
- the initial value of the variable.