Class DetachedThreadLocal<T>

  • All Implemented Interfaces:
    java.lang.Runnable

    public class DetachedThreadLocal<T>
    extends java.lang.Object
    implements java.lang.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.
    • Method Detail

      • get

        public T get()
      • get

        public T get​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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<java.lang.Thread,​T> getBackingMap()
        Returns:
        The weak map that backs this detached thread local.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable