Class ThreadLocalUtilities


  • public final class ThreadLocalUtilities
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clearThreadLocalMemoryForCurrentThread​(java.util.Map<java.lang.ThreadLocal,​java.lang.Object> threadlocalsBefore)
      Removes all ThreadLocal data which has been added to the current thread excluding a specified set of previously existing data.
      static java.util.Map<java.lang.ThreadLocal,​java.lang.Object> extractThreadLocalValuesForCurrentThread()
      Extracts all data currently held by ThreadLocal instances for the current thread.
      • Methods inherited from class java.lang.Object

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

      • clearThreadLocalMemoryForCurrentThread

        public static void clearThreadLocalMemoryForCurrentThread​(java.util.Map<java.lang.ThreadLocal,​java.lang.Object> threadlocalsBefore)
        Removes all ThreadLocal data which has been added to the current thread excluding a specified set of previously existing data.

        This is a workaround for PLA-10329 (java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6625723 ) which is removing all ThreadLocals from current thread that belong to ReentrantReadWriteLocks. Please be aware that this relies on some very dirty reflection work and might break in future.

        Parameters:
        threadlocalsBefore - the data to preserve. see extractThreadLocalValuesForCurrentThread()
      • extractThreadLocalValuesForCurrentThread

        public static java.util.Map<java.lang.ThreadLocal,​java.lang.Object> extractThreadLocalValuesForCurrentThread()
        Extracts all data currently held by ThreadLocal instances for the current thread. Please be aware that this relies on some very dirty reflection work and might break in future.