]> source.dussan.org Git - poi.git/commitdiff
provide way to clear the state on the ThreadLocal used byby ExtractorFactory
authorPJ Fanning <fanningpj@apache.org>
Sat, 11 Feb 2023 12:07:34 +0000 (12:07 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 11 Feb 2023 12:07:34 +0000 (12:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1907581 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java
poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java

index 8bd8b535bc27d61fd2ceeab4c0a822cb4c105e5b..2de39e366914669dbe51e07d64d7898421e718c2 100644 (file)
@@ -102,11 +102,29 @@ public final class POIXMLExtractorFactory implements ExtractorProvider {
     /**
      * Should this thread prefer event based over usermodel based extractors?
      * Will only be used if the All Threads setting is null.
+     *
+     * <p>
+     *     This uses ThreadLocals and these can leak resources when you have a lot of threads.
+     * </p>
+     *
+     * You should always try to call {@link #removeThreadPrefersEventExtractorsSetting()}.
+     *
+     * @see #setAllThreadsPreferEventExtractors
      */
     public static void setThreadPrefersEventExtractors(boolean preferEventExtractors) {
          ExtractorFactory.setThreadPrefersEventExtractors(preferEventExtractors);
     }
 
+    /**
+     * Clears the setting for this thread made by {@link #setThreadPrefersEventExtractors(boolean) }
+     *
+     * @see #setThreadPrefersEventExtractors(boolean)
+     * @since POI 5.2.4
+     */
+    public static void removeThreadPrefersEventExtractorsSetting() {
+        ExtractorFactory.removeThreadPrefersEventExtractorsSetting();
+    }
+
     /**
      * Should all threads prefer event based over usermodel based extractors?
      * If set, will take preference over the Thread level setting.
index 28b81e9cc432749e1729f9eccb14bf054747d948..3e8f0461120ffe5f7c8a78597e7c0b1fdc9c49b0 100644 (file)
@@ -111,12 +111,28 @@ public final class ExtractorFactory {
      * Should this thread prefer event based over usermodel based extractors?
      * Will only be used if the All Threads setting is null.
      *
+     * <p>
+     *     This uses ThreadLocals and these can leak resources when you have a lot of threads.
+     * </p>
+     *
+     * You should always try to call {@link #removeThreadPrefersEventExtractorsSetting()}.
+     *
      * @param preferEventExtractors If this threads should prefer event based extractors.
      */
     public static void setThreadPrefersEventExtractors(boolean preferEventExtractors) {
         threadPreferEventExtractors.set(preferEventExtractors);
     }
 
+    /**
+     * Clears the setting for this thread made by {@link #setThreadPrefersEventExtractors(boolean) }
+     *
+     * @see #setThreadPrefersEventExtractors(boolean)
+     * @since POI 5.2.4
+     */
+    public static void removeThreadPrefersEventExtractorsSetting() {
+        threadPreferEventExtractors.remove();
+    }
+
     /**
      * Should all threads prefer event based over usermodel based extractors?
      * If set, will take preference over the Thread level setting.