]> source.dussan.org Git - poi.git/commitdiff
#59268 - cache typeloader because of OOMs in the jenkins tests
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 24 Jun 2018 07:30:20 +0000 (07:30 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 24 Jun 2018 07:30:20 +0000 (07:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1834236 13f79535-47bb-0310-9956-ffa450edef68

build.xml

index e7e5e5e2e1fcbc832619d2e227655ab8fd64778f..e65567b61f6b4832a769edd9644267d1978997e3 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -871,10 +871,22 @@ under the License.
                 </classpath>
             </xmlbean>
 
-            <replaceregexp byline="true"
-                match="(\s*)public static ([^ ]+) newInstance\(\) \{"
-                replace="\1private static org.apache.xmlbeans.SchemaTypeLoader getTypeLoader() { return org.apache.xmlbeans.XmlBeans.typeLoaderForClassLoader(\2.class.getClassLoader()); }${line.separator}${line.separator}\1public static \2 newInstance\(\) \{"
-            >
+            <local name="loaderMethod"/>
+            <property name="loaderMethod"><![CDATA[
+        private static java.lang.ref.SoftReference<org.apache.xmlbeans.SchemaTypeLoader> typeLoader;
+
+        private static synchronized org.apache.xmlbeans.SchemaTypeLoader getTypeLoader() {
+            org.apache.xmlbeans.SchemaTypeLoader stl = (typeLoader == null) ? null : typeLoader.get();
+            if (stl == null) {
+                stl = org.apache.xmlbeans.XmlBeans.typeLoaderForClassLoader(\2.class.getClassLoader());
+                typeLoader = new java.lang.ref.SoftReference(stl);
+            }
+            return stl;
+        }
+
+        public static \2 newInstance\(\) \{]]></property>
+
+            <replaceregexp byline="true" match="(\s*)public static ([^ ]+) newInstance\(\) \{" replace="${loaderMethod}">
                 <fileset dir="${xmlbean.sources.dir}" includes="**/*.java" excludes="**/impl/**"/>
             </replaceregexp>