Class TryThreadLocal<T>

  • Type Parameters:
    T - Value type

    public class TryThreadLocal<T>
    extends java.lang.ThreadLocal<T>
    Thread-local variable that returns a handle that can be closed.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  TryThreadLocal.Memo
      Remembers to set the value back.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private T initialValue  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TryThreadLocal​(T initialValue)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected T initialValue()  
      static <T> TryThreadLocal<T> of​(T initialValue)
      Creates a TryThreadLocal.
      TryThreadLocal.Memo push​(T value)
      Assigns the value as value for the current thread.
      • Methods inherited from class java.lang.ThreadLocal

        get, remove, set, withInitial
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • initialValue

        private final T initialValue
    • Constructor Detail

      • TryThreadLocal

        private TryThreadLocal​(T initialValue)
    • Method Detail

      • of

        public static <T> TryThreadLocal<T> of​(T initialValue)
        Creates a TryThreadLocal.
        Parameters:
        initialValue - Initial value
      • initialValue

        protected final T initialValue()
        Overrides:
        initialValue in class java.lang.ThreadLocal<T>
      • push

        public TryThreadLocal.Memo push​(T value)
        Assigns the value as value for the current thread. Returns a TryThreadLocal.Memo which, when closed, will assign the value back to the previous value.