public class Hk2ThreadLocal<T> extends Object
ThreadLocal
with
the one major upside of a removeAll()
method that
can be used to remove ALL instances of all thread locals on
ALL threads from any other thread.Constructor and Description |
---|
Hk2ThreadLocal() |
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the value in the current thread's copy of this
thread-local variable.
|
int |
getSize()
Returns the total size of the internal data structure in
terms of entries.
|
protected T |
initialValue()
Returns the current thread's "initial value" for this
thread-local variable.
|
void |
remove()
Removes the current thread's value for this thread-local
variable.
|
void |
removeAll()
Removes all threads current thread's value for this thread-local
variable.
|
void |
set(T value)
Sets the current thread's copy of this thread-local variable
to the specified value.
|
protected T initialValue()
get()
method, unless the thread previously invoked the set(T)
method, in which case the initialValue method will not
be invoked for the thread. Normally, this method is invoked at
most once per thread, but it may be invoked again in case of
subsequent invocations of remove()
followed by get()
.
This implementation simply returns null; if the programmer desires thread-local variables to have an initial value other than null, ThreadLocal must be subclassed, and this method overridden. Typically, an anonymous inner class will be used.
public T get()
initialValue()
method.public void set(T value)
initialValue()
method to set the values of thread-locals.value
- the value to be stored in the current thread's copy of
this thread-local.public void remove()
initialValue()
method,
unless its value is set by the current thread
in the interim. This may result in multiple invocations of the
initialValue method in the current thread.public void removeAll()
initialValue()
method,
unless its value is set by the current thread
in the interim. This may result in multiple invocations of the
initialValue method in the current thread.public int getSize()
Copyright © 2009-2017, Oracle and/or its affiliates. All Rights Reserved.