Class FastThreadLocalThread

  • All Implemented Interfaces:
    java.lang.Runnable

    public class FastThreadLocalThread
    extends java.lang.Thread
    A special Thread that provides fast access to FastThreadLocal variables.
    • 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.
      • 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​(java.lang.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.