diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java index 8bd8b535bc..2de39e3669 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java @@ -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. + * + *
+ * This uses ThreadLocals and these can leak resources when you have a lot of threads. + *
+ * + * 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. diff --git a/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java b/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java index 28b81e9cc4..3e8f046112 100644 --- a/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java @@ -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. * + *+ * This uses ThreadLocals and these can leak resources when you have a lot of threads. + *
+ * + * 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.