Class ThreadLocalTransferHelper

  • Direct Known Subclasses:
    ComponentSuspendable, ThreadSuspendable

    public class ThreadLocalTransferHelper
    extends java.lang.Object
    Helps to transfer registered thread local values between different threads.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.util.Set<java.lang.ThreadLocal<java.lang.Object>> THREADLOCALS
      The registered thread locals.
      protected java.util.Map<java.lang.ThreadLocal<java.lang.Object>,​java.lang.Object> vals
      The thread locals.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void addThreadLocal​(java.lang.ThreadLocal<?> tl)
      Add a thread local that will be automatically copied on thread resumption.
      void afterSwitch()
      Must be called after a thread switch occurs to restore the thread local values.
      void beforeSwitch()
      Must be called before a thread switch occurs to save the thread local values.
      static void removeThreadLocal​(java.lang.ThreadLocal<?> tl)
      Add a thread local that will be automatically copied on thread resumption.
      static void restoreValues​(java.util.Map<java.lang.ThreadLocal<java.lang.Object>,​java.lang.Object> vals)
      Method to be called on new thread on resumption.
      static java.util.Map<java.lang.ThreadLocal<java.lang.Object>,​java.lang.Object> saveValues()
      Method to be called on old thread before thread switch.
      • Methods inherited from class java.lang.Object

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

      • THREADLOCALS

        protected static final java.util.Set<java.lang.ThreadLocal<java.lang.Object>> THREADLOCALS
        The registered thread locals.
      • vals

        protected java.util.Map<java.lang.ThreadLocal<java.lang.Object>,​java.lang.Object> vals
        The thread locals.
    • Constructor Detail

      • ThreadLocalTransferHelper

        public ThreadLocalTransferHelper()
        Create a new transfer helper.
      • ThreadLocalTransferHelper

        public ThreadLocalTransferHelper​(boolean beforeswitch)
        Create a new transfer helper.
    • Method Detail

      • saveValues

        public static java.util.Map<java.lang.ThreadLocal<java.lang.Object>,​java.lang.Object> saveValues()
        Method to be called on old thread before thread switch.
      • restoreValues

        public static void restoreValues​(java.util.Map<java.lang.ThreadLocal<java.lang.Object>,​java.lang.Object> vals)
        Method to be called on new thread on resumption.
      • addThreadLocal

        public static void addThreadLocal​(java.lang.ThreadLocal<?> tl)
        Add a thread local that will be automatically copied on thread resumption.
      • removeThreadLocal

        public static void removeThreadLocal​(java.lang.ThreadLocal<?> tl)
        Add a thread local that will be automatically copied on thread resumption.
      • beforeSwitch

        public void beforeSwitch()
        Must be called before a thread switch occurs to save the thread local values.
      • afterSwitch

        public void afterSwitch()
        Must be called after a thread switch occurs to restore the thread local values.