- java.lang.Object
- 
- io.netty5.util.concurrent.FastThreadLocal<V>
 
- 
- Type Parameters:
- V- the type of the thread-local variable
 
 public class FastThreadLocal<V> extends Object A special variant ofThreadLocalthat yields higher access performance when accessed from aFastThreadLocalThread.Internally, a FastThreadLocaluses 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 FastThreadLocalThreador its subtype. By default, all threads created byDefaultThreadFactoryareFastThreadLocalThreaddue 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 regularThreadLocal.- See Also:
- ThreadLocal
 
- 
- 
Constructor SummaryConstructors Constructor Description FastThreadLocal()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voiddestroy()Destroys the data structure that keeps allFastThreadLocalvariables accessed from non-FastThreadLocalThreads.Vget()Returns the current value for the current threadVgetIfExists()Returns the current value for the current thread if it exists,nullotherwise.protected VinitialValue()Returns the initial value for this thread-local variable.booleanisSet()Returnstrueif and only if this thread-local variable is set.protected voidonRemoval(V value)Invoked when this thread local variable is removed byremove().voidremove()Sets the value to uninitialized for the specified thread local map.static voidremoveAll()Removes allFastThreadLocalvariables bound to the current thread.voidset(V value)Set the value for the current thread.static intsize()Returns the number of thread local variables bound to the current thread.
 
- 
- 
- 
Method Detail- 
removeAllpublic static void removeAll() Removes allFastThreadLocalvariables 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.
 - 
sizepublic static int size() Returns the number of thread local variables bound to the current thread.
 - 
destroypublic static void destroy() Destroys the data structure that keeps allFastThreadLocalvariables 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.
 - 
getpublic final V get() Returns the current value for the current thread
 - 
getIfExistspublic final V getIfExists() Returns the current value for the current thread if it exists,nullotherwise.
 - 
setpublic final void set(V value) Set the value for the current thread.
 - 
isSetpublic final boolean isSet() Returnstrueif and only if this thread-local variable is set.
 - 
removepublic 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().
 - 
initialValueprotected V initialValue() throws Exception Returns the initial value for this thread-local variable.- Throws:
- Exception
 
 - 
onRemovalprotected void onRemoval(V value) throws Exception Invoked when this thread local variable is removed byremove(). Be aware thatremove()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.- Throws:
- Exception
 
 
- 
 
-