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 | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| public static void | destroy()
Destroys the data structure that keeps all |
| public final V | |
| public final V | |
| private V | |
| protected V | |
| public final boolean | |
| private boolean | isSet(InternalThreadLocalMap threadLocalMap)
Returns |
| protected void | |
| public final void | |
| private void | remove(InternalThreadLocalMap threadLocalMap)
Sets the value to uninitialized for the specified thread local map. |
| public static void | |
| private static void | |
| public final void | |
| private void | set(InternalThreadLocalMap threadLocalMap, V value)
Set the value for the specified thread local map. |
| private void | |
| public static int |
| index | back to summary |
|---|---|
| private final int index | |
| variablesToRemoveIndex | back to summary |
|---|---|
| private static final int variablesToRemoveIndex | |
| FastThreadLocal | back to summary |
|---|---|
| public FastThreadLocal() | |
| addToVariablesToRemove | back to summary |
|---|---|
private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)
| |
| 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
| |
| 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) | |
| 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 |
|---|---|
| private boolean isSet(InternalThreadLocalMap threadLocalMap) 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 |
|---|---|
| private void remove(InternalThreadLocalMap threadLocalMap) 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) | |
| set | back to summary |
|---|---|
| public final void set(V value) Set the value for the current thread. | |
| set | back to summary |
|---|---|
| private void set(InternalThreadLocalMap threadLocalMap, V value) 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) | |
| size | back to summary |
|---|---|
| public static int size() Returns the number of thread local variables bound to the current thread. | |