fix #5048 disabling url caching for jdk1.8 to avoid memleak
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 6 Nov 2019 17:12:14 +0000 (18:12 +0100)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 6 Nov 2019 17:13:07 +0000 (18:13 +0100)
src/main/java/eu/etaxonomy/cdm/server/Bootloader.java

index c91db049b4e4ff30b0b4f768906c9a5113aec7d2..784daaa0c731379b9bb8abc56734d86ae0fcd589 100644 (file)
@@ -31,6 +31,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.lang.management.ManagementFactory;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -469,6 +470,9 @@ public final class Bootloader {
 //        QueuedThreadPool threadPool = new QueuedThreadPool(JvmManager.availableProcessors() +  + 200);
 //        server = new Server(threadPool);
         server = new Server();
+
+        jdk8MemleakFix();
+
         server.addLifeCycleListener(instanceManager);
         ServerConnector connector=new ServerConnector(server);
         connector.setPort(httpPort);
@@ -563,6 +567,23 @@ public final class Bootloader {
         }
     }
 
+    /**
+     * jdk8 memleak workaround: disable url caching
+     *  see https://dev.e-taxonomy.eu/redmine/issues/5048
+     *
+     * @throws IOException
+     * @throws MalformedURLException
+     */
+    private void jdk8MemleakFix() throws IOException, MalformedURLException {
+        String javaVersion = System.getProperty("java.version");
+        if(javaVersion.startsWith("1.8")){
+            logger.info("jdk8 detected (" + javaVersion + ") disabling url caching to avoid memory leak.");
+            org.eclipse.jetty.util.resource.Resource.setDefaultUseCaches(false);
+            File tmpio = new File(System.getProperty("java.io.tmpdir"));
+            tmpio.toURI().toURL().openConnection().setDefaultUseCaches(false);
+        }
+    }
+
     /**
      * @param classpath
      */