Package io.netty.util.concurrent
Class FastThreadLocalThread
- java.lang.Object
-
- java.lang.Thread
-
- io.netty.util.concurrent.FastThreadLocalThread
-
- All Implemented Interfaces:
java.lang.Runnable
public class FastThreadLocalThread extends java.lang.ThreadA specialThreadthat provides fast access toFastThreadLocalvariables.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFastThreadLocalThread.FallbackThreadSetImmutable, thread-safe helper class that wrapsLongLongHashMap
-
Field Summary
Fields Modifier and Type Field Description private booleancleanupFastThreadLocalsprivate static java.util.concurrent.atomic.AtomicReference<FastThreadLocalThread.FallbackThreadSet>fallbackThreadsSet of thread IDs that are treated likeFastThreadLocalThread.private static InternalLoggerloggerprivate InternalThreadLocalMapthreadLocalMap
-
Constructor Summary
Constructors Constructor Description FastThreadLocalThread()FastThreadLocalThread(java.lang.Runnable target)FastThreadLocalThread(java.lang.Runnable target, java.lang.String name)FastThreadLocalThread(java.lang.String name)FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.Runnable target)FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name, long stackSize)FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleancurrentThreadHasFastThreadLocal()Returnstrueif this thread supportsFastThreadLocal.static booleancurrentThreadWillCleanupFastThreadLocals()private static booleanisFastThreadLocalVirtualThread()booleanpermitBlockingCalls()Query whether this thread is allowed to perform blocking calls or not.static voidrunWithFastThreadLocal(java.lang.Runnable runnable)Run the given task withFastThreadLocalsupport.voidsetThreadLocalMap(InternalThreadLocalMap threadLocalMap)Sets the internal data structure that keeps the thread-local variables bound to this thread.InternalThreadLocalMapthreadLocalMap()Returns the internal data structure that keeps the thread-local variables bound to this thread.booleanwillCleanupFastThreadLocals()Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()insteadstatic booleanwillCleanupFastThreadLocals(java.lang.Thread thread)Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()instead-
Methods inherited from class java.lang.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, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
fallbackThreads
private static final java.util.concurrent.atomic.AtomicReference<FastThreadLocalThread.FallbackThreadSet> fallbackThreads
Set of thread IDs that are treated likeFastThreadLocalThread.
-
cleanupFastThreadLocals
private final boolean cleanupFastThreadLocals
-
threadLocalMap
private InternalThreadLocalMap threadLocalMap
-
-
Constructor Detail
-
FastThreadLocalThread
public FastThreadLocalThread()
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.Runnable target)
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.Runnable target)
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.String name)
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.String name)
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.Runnable target, java.lang.String name)
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)
-
FastThreadLocalThread
public FastThreadLocalThread(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name, long stackSize)
-
-
Method Detail
-
threadLocalMap
public final InternalThreadLocalMap 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
public final void setThreadLocalMap(InternalThreadLocalMap threadLocalMap)
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 public boolean willCleanupFastThreadLocals()
Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()instead
-
willCleanupFastThreadLocals
@Deprecated public static boolean willCleanupFastThreadLocals(java.lang.Thread thread)
Deprecated.UsecurrentThreadWillCleanupFastThreadLocals()instead
-
currentThreadWillCleanupFastThreadLocals
public static boolean currentThreadWillCleanupFastThreadLocals()
-
currentThreadHasFastThreadLocal
public static boolean currentThreadHasFastThreadLocal()
Returnstrueif this thread supportsFastThreadLocal.
-
isFastThreadLocalVirtualThread
private static boolean isFastThreadLocalVirtualThread()
-
runWithFastThreadLocal
public static void runWithFastThreadLocal(java.lang.Runnable runnable)
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 overridden by a subclass.
-
-