Class FastThreadLocalThread
java.lang.Object
java.lang.Thread
io.netty.util.concurrent.FastThreadLocalThread
- All Implemented Interfaces:
Runnable
A special
Thread that provides fast access to FastThreadLocal variables.-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionFastThreadLocalThread(Runnable target) FastThreadLocalThread(Runnable target, String name) FastThreadLocalThread(String name) FastThreadLocalThread(ThreadGroup group, Runnable target) FastThreadLocalThread(ThreadGroup group, Runnable target, String name) FastThreadLocalThread(ThreadGroup group, Runnable target, String name, long stackSize) FastThreadLocalThread(ThreadGroup group, String name) -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturnstrueif this thread supportsFastThreadLocal.static booleanbooleanQuery whether this thread is allowed to perform blocking calls or not.static voidrunWithFastThreadLocal(Runnable runnable) Run the given task withFastThreadLocalsupport.final voidsetThreadLocalMap(InternalThreadLocalMap threadLocalMap) Sets the internal data structure that keeps the thread-local variables bound to this thread.final InternalThreadLocalMapReturns the internal data structure that keeps the thread-local variables bound to this thread.booleanDeprecated.static booleanwillCleanupFastThreadLocals(Thread thread) Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()insteadMethods inherited from class Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
Constructor Details
-
FastThreadLocalThread
public FastThreadLocalThread() -
FastThreadLocalThread
-
FastThreadLocalThread
-
FastThreadLocalThread
-
FastThreadLocalThread
-
FastThreadLocalThread
-
FastThreadLocalThread
-
FastThreadLocalThread
-
-
Method Details
-
threadLocalMap
Returns the internal data structure that keeps the thread-local variables bound to this thread. Note that this method is for internal use only, and thus is subject to change at any time. -
setThreadLocalMap
Sets the internal data structure that keeps the thread-local variables bound to this thread. Note that this method is for internal use only, and thus is subject to change at any time. -
willCleanupFastThreadLocals
Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()instead -
willCleanupFastThreadLocals
Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()instead -
currentThreadWillCleanupFastThreadLocals
public static boolean currentThreadWillCleanupFastThreadLocals() -
currentThreadHasFastThreadLocal
public static boolean currentThreadHasFastThreadLocal()Returnstrueif this thread supportsFastThreadLocal. -
runWithFastThreadLocal
Run the given task withFastThreadLocalsupport. This call should wrap the runnable for any thread that is long-running enough to make treating it as aFastThreadLocalThreadreasonable, but that can't actually extend this class (e.g. because it's a virtual thread). Netty will use optimizations for recyclers and allocators as if this was aFastThreadLocalThread.This method will clean up any
FastThreadLocals at the end, andcurrentThreadWillCleanupFastThreadLocals()will returntrue.At the moment,
FastThreadLocaluses normalThreadLocalas the backing storage here, but in the future this may be replaced with scoped values, if semantics can be preserved and performance is good.- Parameters:
runnable- The task to run
-
permitBlockingCalls
public boolean permitBlockingCalls()Query whether this thread is allowed to perform blocking calls or not.FastThreadLocalThreads are often used in event-loops, where blocking calls are forbidden in order to prevent event-loop stalls, so this method returnsfalseby default.Subclasses of
FastThreadLocalThreadcan override this method if they are not meant to be used for running event-loops.- Returns:
false, unless overriden by a subclass.
-
currentThreadWillCleanupFastThreadLocals()instead