Top Description Fields Constructors Methods
io.netty.util.concurrent

public Class FastThreadLocal<V>

extends Object
Class Inheritance
Type Parameters
<V>
the type of the thread-local variable
Imports
io.netty.util.internal.InternalThreadLocalMap, .PlatformDependent, java.util.Collections, .IdentityHashMap, .Set

A special variant of 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.

See Also
ThreadLocal

Field Summary

Modifier and TypeField and Description
private final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod 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 FastThreadLocal variables accessed from non-FastThreadLocalThreads.

public final V
get()

Returns the current value for the current thread

public final V
get(InternalThreadLocalMap threadLocalMap)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
Returns the current value for the specified thread local map.
public final V
getIfExists()

Returns the current value for the current thread if it exists, null otherwise.

private V
initialize(InternalThreadLocalMap threadLocalMap)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
protected V
initialValue()

Returns the initial value for this thread-local variable.

public final boolean
isSet()

Returns true if and only if this thread-local variable is set.

public final boolean
isSet(InternalThreadLocalMap threadLocalMap)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
Returns true if and only if this thread-local variable is set.
protected void
onRemoval(V value)

Invoked when this thread local variable is removed by remove().

public final void
remove()

Sets the value to uninitialized for the specified thread local map.

public final void
remove(InternalThreadLocalMap threadLocalMap)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
Sets the value to uninitialized for the specified thread local map.
public static void
removeAll()

Removes all FastThreadLocal variables bound to the current thread.

private static void
removeFromVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
public final void
set(V value)

Set the value for the current thread.

public final void
set(InternalThreadLocalMap threadLocalMap, V value)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
Set the value for the specified thread local map.
private void
setKnownNotUnset(InternalThreadLocalMap threadLocalMap, V value)

Deprecated as a consequence of InternalThreadLocalMap being deprecated.
public static int
size()

Returns the number of thread local variables bound to the current thread.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
private final int index

Constructor Detail

FastThreadLocalback to summary
public FastThreadLocal()

Method Detail

addToVariablesToRemoveback to summary
private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:unchecked
destroyback to summary
public static void destroy()

Destroys the data structure that keeps all FastThreadLocal variables accessed from non-FastThreadLocalThreads. This operation is useful when you are in a container environment, and you do not want to leave the thread local variables in the threads you do not manage. Call this method when your application is being unloaded from the container.

getback to summary
public final V get()

Returns the current value for the current thread

Annotations
@SuppressWarnings:unchecked
getback to summary
public final V get(InternalThreadLocalMap threadLocalMap)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

Returns the current value for the specified thread local map. The specified thread local map must be for the current thread.

Annotations
@SuppressWarnings:unchecked
getIfExistsback to summary
public final V getIfExists()

Returns the current value for the current thread if it exists, null otherwise.

Annotations
@SuppressWarnings:unchecked
initializeback to summary
private V initialize(InternalThreadLocalMap threadLocalMap)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

initialValueback to summary
protected V initialValue() throws Exception

Returns the initial value for this thread-local variable.

isSetback to summary
public final boolean isSet()

Returns true if and only if this thread-local variable is set.

isSetback to summary
public final boolean isSet(InternalThreadLocalMap threadLocalMap)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

Returns true if and only if this thread-local variable is set. The specified thread local map must be for the current thread.

onRemovalback to summary
protected void onRemoval(V value) throws Exception

Invoked when this thread local variable is removed by remove(). Be aware that remove() is not guaranteed to be called when the `Thread` completes which means you can not depend on this for cleanup of the resources in the case of `Thread` completion.

removeback 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().

removeback to summary
public final void remove(InternalThreadLocalMap threadLocalMap)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

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.

Annotations
@SuppressWarnings:unchecked
removeAllback to summary
public static void removeAll()

Removes all FastThreadLocal variables bound to the current thread. This operation is useful when you are in a container environment, and you don't want to leave the thread local variables in the threads you do not manage.

removeFromVariablesToRemoveback to summary
private static void removeFromVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

setback to summary
public final void set(V value)

Set the value for the current thread.

setback to summary
public final void set(InternalThreadLocalMap threadLocalMap, V value)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

Set the value for the specified thread local map. The specified thread local map must be for the current thread.

setKnownNotUnsetback to summary
private void setKnownNotUnset(InternalThreadLocalMap threadLocalMap, V value)

Deprecated

as a consequence of InternalThreadLocalMap being deprecated. See corresponding docs for further information.

See Also
InternalThreadLocalMap#setIndexedVariable(int, Object).
sizeback to summary
public static int size()

Returns the number of thread local variables bound to the current thread.