Class ThreadLocalUtil


  • public class ThreadLocalUtil
    extends java.lang.Object
    Small utility to allow to remove references held in ThreadLocals. This is sometimes necessary, e.g. when returning threads into a global thread pool. For each usage of ThreadLocal, a cleaner is registered via registerCleaner().
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clearAllThreadLocals()
      Clear ThreadLocals of the current thread.
      static void registerCleaner​(java.lang.Runnable cleaner)
      Intended for internal use only so other modules of Apache POi can add cleaners.
      • Methods inherited from class java.lang.Object

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

      • clearAllThreadLocals

        public static void clearAllThreadLocals()
        Clear ThreadLocals of the current thread. This can be used to clean out a thread before "returning" it to a thread-pool or a Web-Container like Tomcat. Usually org.apache.xmlbeans.ThreadLocalUtil#clearAllThreadLocals() should be called as well to clear out some more ThreadLocals which are created by the XMLBeans library internally.
      • registerCleaner

        @Internal
        public static void registerCleaner​(java.lang.Runnable cleaner)
        Intended for internal use only so other modules of Apache POi can add cleaners.
        Parameters:
        cleaner - a runnable which clears some thread-local that is located outside of the "poi" module.