Class DetachedThreadLocal<T>

java.lang.Object
org.mockito.internal.util.concurrent.DetachedThreadLocal<T>
All Implemented Interfaces:
Runnable

public class DetachedThreadLocal<T> extends Object implements Runnable

A detached local that allows for explicit control of setting and removing values from a thread-local context.

Instances of this class are non-blocking and fully thread safe.
  • Field Details

  • Constructor Details

  • Method Details

    • get

      public T get()
    • get

      public T get(Thread thread)
      Parameters:
      thread - The thread for which to set a thread-local value.
      Returns:
      The value associated with this thread.
    • set

      public void set(T value)
    • clear

      public void clear()
    • clearAll

      public void clearAll()
      Clears all thread local references for all threads.
    • pushTo

      public T pushTo(Thread thread)
      Parameters:
      thread - The thread to which this thread's thread local value should be pushed.
      Returns:
      The value being set.
    • fetchFrom

      public T fetchFrom(Thread thread)
      Parameters:
      thread - The thread from which the thread thread local value should be fetched.
      Returns:
      The value being set.
    • define

      public void define(Thread thread, T value)
      Parameters:
      thread - The thread for which to set a thread-local value.
      value - The value to set.
    • initialValue

      protected T initialValue(Thread thread)
      Parameters:
      thread - The thread for which an initial value is created.
      Returns:
      The initial value for any thread local. If no default is set, the default value is null.
    • inheritValue

      protected T inheritValue(T value)
      Parameters:
      value - The value that is inherited.
      Returns:
      The inherited value.
    • getBackingMap

      public WeakConcurrentMap<Thread,T> getBackingMap()
      Returns:
      The weak map that backs this detached thread local.
    • run

      public void run()
      Specified by:
      run in interface Runnable