Class ThreadLocal<T>

  • Type Parameters:
    T - the type of the thread local variable

    public class ThreadLocal<T>
    extends Object
    This class was written by Robert Elliot and is originally located at https://github.com/Mahoney/lidalia-lang

    A ThreadLocal that has no ClassLoader leaks associated with it and does not permit null.

    Values for all Threads can be reset from any Thread.

    • Constructor Detail

      • ThreadLocal

        public ThreadLocal​(T initialValue)
        Parameters:
        initialValue - the value this thread local will initially have for all Threads. This should not be mutable, as it will be shared between all Threads.
      • ThreadLocal

        public ThreadLocal​(Supplier<T> initialValueCreator)
        Parameters:
        initialValueCreator - a Supplier whose get method is called on a per Thread basis in order to establish the initial value for that Thread, allowing a different initial instance per Thread.
    • Method Detail

      • set

        public void set​(T value)
        Parameters:
        value - the new value for the calling Thread - does not affect the value for any other Thread.
      • get

        public T get()
        Returns:
        the value for the calling Thread, or the initial value if this has not been set or has been removed.
      • remove

        public void remove()
        Removes the value for the calling Thread. A subsequent call to get() will return the initial value.
      • reset

        public void reset()
        Removes the values for ALL Threads. Subsequent calls to get() will return the initial value.