Class InternalThreadLocal<V>

java.lang.Object
java.lang.ThreadLocal<V>
org.apache.dubbo.common.threadlocal.InternalThreadLocal<V>

public class InternalThreadLocal<V> extends ThreadLocal<V>
InternalThreadLocal A special variant of ThreadLocal that yields higher access performance when accessed from a InternalThread.

Internally, a InternalThread uses a constant index in an array, instead of using hash code and hash table, to look for a variable. Although seemingly very subtle, it yields slight performance advantage over using a hash table, and it is useful when accessed frequently.

This design is learning from which is in Netty.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
     
    final V
    get()
    Returns the current value for the current thread
    final V
     
    final void
    Sets the value to uninitialized; a proceeding call to get() will trigger a call to initialValue().
    final void
    Sets the value to uninitialized for the specified thread local map; a proceeding call to get() will trigger a call to initialValue().
    static void
    Removes all InternalThreadLocal variables bound to the current thread.
    final void
    set(V value)
    Sets the value for the current thread.
    static int
    Returns the number of thread local variables bound to the current thread.

    Methods inherited from class java.lang.ThreadLocal

    withInitial

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InternalThreadLocal

      public InternalThreadLocal()
  • Method Details

    • removeAll

      public static void removeAll()
      Removes all InternalThreadLocal variables bound to the current thread. This operation is useful when you are in a container environment, and you don't want to leave the thread local variables in the threads you do not manage.
    • size

      public static int size()
      Returns the number of thread local variables bound to the current thread.
    • destroy

      public static void destroy()
    • get

      public final V get()
      Returns the current value for the current thread
      Overrides:
      get in class ThreadLocal<V>
    • getWithoutInitialize

      public final V getWithoutInitialize()
    • set

      public final void set(V value)
      Sets the value for the current thread.
      Overrides:
      set in class ThreadLocal<V>
    • remove

      public final void remove()
      Sets the value to uninitialized; a proceeding call to get() will trigger a call to initialValue().
      Overrides:
      remove in class ThreadLocal<V>
    • remove

      public final void remove(InternalThreadLocalMap threadLocalMap)
      Sets the value to uninitialized for the specified thread local map; a proceeding call to get() will trigger a call to initialValue(). The specified thread local map must be for the current thread.