Class FastThreadLocalThread

java.lang.Object
java.lang.Thread
io.netty.util.concurrent.FastThreadLocalThread
All Implemented Interfaces:
Runnable

public class FastThreadLocalThread extends Thread
A special Thread that provides fast access to FastThreadLocal variables.
  • Constructor Details

    • FastThreadLocalThread

      public FastThreadLocalThread()
    • FastThreadLocalThread

      public FastThreadLocalThread(Runnable target)
    • FastThreadLocalThread

      public FastThreadLocalThread(ThreadGroup group, Runnable target)
    • FastThreadLocalThread

      public FastThreadLocalThread(String name)
    • FastThreadLocalThread

      public FastThreadLocalThread(ThreadGroup group, String name)
    • FastThreadLocalThread

      public FastThreadLocalThread(Runnable target, String name)
    • FastThreadLocalThread

      public FastThreadLocalThread(ThreadGroup group, Runnable target, String name)
    • FastThreadLocalThread

      public FastThreadLocalThread(ThreadGroup group, Runnable target, String name, long stackSize)
  • Method Details

    • 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()
      Returns true if FastThreadLocal.removeAll() will be called once Thread.run() completes.
    • willCleanupFastThreadLocals

      @Deprecated public static boolean willCleanupFastThreadLocals(Thread thread)
      Returns true if FastThreadLocal.removeAll() will be called once Thread.run() completes.
    • currentThreadWillCleanupFastThreadLocals

      public static boolean currentThreadWillCleanupFastThreadLocals()
      Returns true if FastThreadLocal.removeAll() will be called once Thread.run() completes.
    • currentThreadHasFastThreadLocal

      public static boolean currentThreadHasFastThreadLocal()
      Returns true if this thread supports FastThreadLocal.
    • runWithFastThreadLocal

      public static void runWithFastThreadLocal(Runnable runnable)
      Run the given task with FastThreadLocal support. This call should wrap the runnable for any thread that is long-running enough to make treating it as a FastThreadLocalThread reasonable, 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 a FastThreadLocalThread.

      This method will clean up any FastThreadLocals at the end, and currentThreadWillCleanupFastThreadLocals() will return true.

      At the moment, FastThreadLocal uses normal ThreadLocal as 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 returns false by default.

      Subclasses of FastThreadLocalThread can override this method if they are not meant to be used for running event-loops.

      Returns:
      false, unless overriden by a subclass.