ThreadLocal
that yields higher access performance when accessed from a
FastThreadLocalThread
.
Internally, a FastThreadLocal
uses a constant index in an array, instead of using hash code and hash table,
to look for a variable. Although seemingly very subtle, it yields slight performance advantage over using a hash
table, and it is useful when accessed frequently.
To take advantage of this thread-local variable, your thread must be a FastThreadLocalThread
or its subtype.
By default, all threads created by DefaultThreadFactory
are FastThreadLocalThread
due to this reason.
Note that the fast path is only possible on threads that extend FastThreadLocalThread
, because it requires
a special field to store the necessary state. An access by any other kind of thread falls back to a regular
ThreadLocal
.
ThreadLocal
Modifier and Type | Field and Description |
---|---|
private final int |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
private static void | addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)
Deprecated
as a consequence of
InternalThreadLocalMap being deprecated.
|
public static void | destroy()
Destroys the data structure that keeps all |
public final V | |
public final V | get(InternalThreadLocalMap threadLocalMap)
Deprecated
as a consequence of
Returns the current value for the specified thread local map.
InternalThreadLocalMap being deprecated.
|
public final V | |
private V | initialize(InternalThreadLocalMap threadLocalMap)
Deprecated
as a consequence of
InternalThreadLocalMap being deprecated.
|
protected V | |
public final boolean | |
public final boolean | isSet(InternalThreadLocalMap threadLocalMap)
Deprecated
as a consequence of
Returns InternalThreadLocalMap being deprecated.
true if and only if this thread-local variable is set.
|
protected void | |
public final void | |
public final void | remove(InternalThreadLocalMap threadLocalMap)
Deprecated
as a consequence of
Sets the value to uninitialized for the specified thread local map.
InternalThreadLocalMap being deprecated.
|
public static void | |
private static void | removeFromVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)
Deprecated
as a consequence of
InternalThreadLocalMap being deprecated.
|
public final void | |
public final void | set(InternalThreadLocalMap threadLocalMap, V value)
Deprecated
as a consequence of
Set the value for the specified thread local map.
InternalThreadLocalMap being deprecated.
|
private void | setKnownNotUnset(InternalThreadLocalMap threadLocalMap, V value)
Deprecated
as a consequence of
InternalThreadLocalMap being deprecated.
|
public static int |
index | back to summary |
---|---|
private final int index |
FastThreadLocal | back to summary |
---|---|
public FastThreadLocal() |
addToVariablesToRemove | back to summary |
---|---|
private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)
Deprecated as a consequence of
|
destroy | back to summary |
---|---|
public static void destroy() Destroys the data structure that keeps all |
get | back to summary |
---|---|
public final V get() Returns the current value for the current thread
|
get | back to summary |
---|---|
public final V get(InternalThreadLocalMap threadLocalMap)
Deprecated as a consequence of Returns the current value for the specified thread local map. The specified thread local map must be for the current thread.
|
getIfExists | back to summary |
---|---|
public final V getIfExists() Returns the current value for the current thread if it exists,
|
initialize | back to summary |
---|---|
private V initialize(InternalThreadLocalMap threadLocalMap)
Deprecated as a consequence of |
initialValue | back to summary |
---|---|
protected V initialValue() throws Exception Returns the initial value for this thread-local variable. |
isSet | back to summary |
---|---|
public final boolean isSet() Returns |
isSet | back to summary |
---|---|
public final boolean isSet(InternalThreadLocalMap threadLocalMap)
Deprecated as a consequence of Returns |
onRemoval | back to summary |
---|---|
protected void onRemoval(V value) throws Exception Invoked when this thread local variable is removed by |
remove | back to summary |
---|---|
public final void remove() Sets the value to uninitialized for the specified thread local map. After this, any subsequent call to get() will trigger a new call to initialValue(). |
remove | back to summary |
---|---|
public final void remove(InternalThreadLocalMap threadLocalMap)
Deprecated as a consequence of Sets the value to uninitialized for the specified thread local map. After this, any subsequent call to get() will trigger a new call to initialValue(). The specified thread local map must be for the current thread.
|
removeAll | back to summary |
---|---|
public static void removeAll() Removes all |
removeFromVariablesToRemove | back to summary |
---|---|
private static void removeFromVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)
Deprecated as a consequence of |
set | back to summary |
---|---|
public final void set(V value) Set the value for the current thread. |
set | back to summary |
---|---|
public final void set(InternalThreadLocalMap threadLocalMap, V value)
Deprecated as a consequence of Set the value for the specified thread local map. The specified thread local map must be for the current thread. |
setKnownNotUnset | back to summary |
---|---|
private void setKnownNotUnset(InternalThreadLocalMap threadLocalMap, V value)
Deprecated as a consequence of |
size | back to summary |
---|---|
public static int size() Returns the number of thread local variables bound to the current thread. |