Home / Class/ FastThreadLocalThread Class — netty Architecture

FastThreadLocalThread Class — netty Architecture

Architecture documentation for the FastThreadLocalThread class in FastThreadLocalThread.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2feb1cd5_2395_f297_19e0_09fabbc500ff["FastThreadLocalThread"]
  503fa76d_84e6_5577_f000_e71e9d75cfbc["FastThreadLocalThread.java"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|defined in| 503fa76d_84e6_5577_f000_e71e9d75cfbc
  9a316999_7130_bfe9_1c4c_2b35afdad7af["FastThreadLocalThread()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| 9a316999_7130_bfe9_1c4c_2b35afdad7af
  ba194f9c_1064_fb9a_4d90_f55f8f3971c1["InternalThreadLocalMap()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| ba194f9c_1064_fb9a_4d90_f55f8f3971c1
  d2f215f1_60e8_fd7c_c2b0_e74250411e5b["setThreadLocalMap()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| d2f215f1_60e8_fd7c_c2b0_e74250411e5b
  a1dcfe07_1ba0_ddfc_a901_67a5d2b1be2f["willCleanupFastThreadLocals()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| a1dcfe07_1ba0_ddfc_a901_67a5d2b1be2f
  84a26bad_2503_3442_66cd_aac6154013cb["currentThreadWillCleanupFastThreadLocals()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| 84a26bad_2503_3442_66cd_aac6154013cb
  bd6323d6_3ffe_e3ce_1b1e_8e95bba76c2f["currentThreadHasFastThreadLocal()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| bd6323d6_3ffe_e3ce_1b1e_8e95bba76c2f
  9f44e7b5_19cd_7006_b866_f628598a18f8["isFastThreadLocalVirtualThread()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| 9f44e7b5_19cd_7006_b866_f628598a18f8
  975ee699_9cd3_a96e_0cf6_88607760d9ab["runWithFastThreadLocal()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| 975ee699_9cd3_a96e_0cf6_88607760d9ab
  9772131a_f024_5aff_52ec_021dad5dd4cb["permitBlockingCalls()"]
  2feb1cd5_2395_f297_19e0_09fabbc500ff -->|method| 9772131a_f024_5aff_52ec_021dad5dd4cb

Relationship Graph

Source Code

common/src/main/java/io/netty/util/concurrent/FastThreadLocalThread.java lines 28–256

public class FastThreadLocalThread extends Thread {

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(FastThreadLocalThread.class);

    /**
     * Set of thread IDs that are treated like {@link FastThreadLocalThread}.
     */
    private static final AtomicReference<FallbackThreadSet> fallbackThreads =
            new AtomicReference<>(FallbackThreadSet.EMPTY);

    // This will be set to true if we have a chance to wrap the Runnable.
    private final boolean cleanupFastThreadLocals;

    private InternalThreadLocalMap threadLocalMap;

    public FastThreadLocalThread() {
        cleanupFastThreadLocals = false;
    }

    public FastThreadLocalThread(Runnable target) {
        super(FastThreadLocalRunnable.wrap(target));
        cleanupFastThreadLocals = true;
    }

    public FastThreadLocalThread(ThreadGroup group, Runnable target) {
        super(group, FastThreadLocalRunnable.wrap(target));
        cleanupFastThreadLocals = true;
    }

    public FastThreadLocalThread(String name) {
        super(name);
        cleanupFastThreadLocals = false;
    }

    public FastThreadLocalThread(ThreadGroup group, String name) {
        super(group, name);
        cleanupFastThreadLocals = false;
    }

    public FastThreadLocalThread(Runnable target, String name) {
        super(FastThreadLocalRunnable.wrap(target), name);
        cleanupFastThreadLocals = true;
    }

    public FastThreadLocalThread(ThreadGroup group, Runnable target, String name) {
        super(group, FastThreadLocalRunnable.wrap(target), name);
        cleanupFastThreadLocals = true;
    }

    public FastThreadLocalThread(ThreadGroup group, Runnable target, String name, long stackSize) {
        super(group, FastThreadLocalRunnable.wrap(target), name, stackSize);
        cleanupFastThreadLocals = true;
    }

    /**
     * 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.
     */
    public final InternalThreadLocalMap threadLocalMap() {
        if (this != Thread.currentThread() && logger.isWarnEnabled()) {
            logger.warn(new RuntimeException("It's not thread-safe to get 'threadLocalMap' " +
                    "which doesn't belong to the caller thread"));
        }
        return 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.
     */
    public final void setThreadLocalMap(InternalThreadLocalMap threadLocalMap) {
        if (this != Thread.currentThread() && logger.isWarnEnabled()) {
            logger.warn(new RuntimeException("It's not thread-safe to set 'threadLocalMap' " +
                    "which doesn't belong to the caller thread"));
        }
        this.threadLocalMap = threadLocalMap;
    }

    /**
     * Returns {@code true} if {@link FastThreadLocal#removeAll()} will be called once {@link #run()} completes.
     *

Frequently Asked Questions

What is the FastThreadLocalThread class?
FastThreadLocalThread is a class in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/FastThreadLocalThread.java.
Where is FastThreadLocalThread defined?
FastThreadLocalThread is defined in common/src/main/java/io/netty/util/concurrent/FastThreadLocalThread.java at line 28.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free