Revision bbe6c98f
Added by Andreas Kohlbecker over 4 years ago
src/main/java/eu/etaxonomy/cdm/server/Bootloader.java | ||
---|---|---|
31 | 31 |
import java.io.InputStreamReader; |
32 | 32 |
import java.io.OutputStream; |
33 | 33 |
import java.lang.management.ManagementFactory; |
34 |
import java.lang.reflect.InvocationTargetException; |
|
34 | 35 |
import java.net.MalformedURLException; |
35 | 36 |
import java.net.URL; |
36 | 37 |
import java.util.ArrayList; |
... | ... | |
471 | 472 |
// server = new Server(threadPool); |
472 | 473 |
server = new Server(); |
473 | 474 |
|
474 |
jdk8MemleakFix(); |
|
475 |
jdk8MemleakFixServer();
|
|
475 | 476 |
|
476 | 477 |
server.addLifeCycleListener(instanceManager); |
477 | 478 |
ServerConnector connector=new ServerConnector(server); |
... | ... | |
574 | 575 |
* @throws IOException |
575 | 576 |
* @throws MalformedURLException |
576 | 577 |
*/ |
577 |
private void jdk8MemleakFix() throws IOException, MalformedURLException { |
|
578 |
private void jdk8MemleakFixServer() throws IOException, MalformedURLException {
|
|
578 | 579 |
String javaVersion = System.getProperty("java.version"); |
579 | 580 |
if(javaVersion.startsWith("1.8")){ |
580 |
logger.info("jdk8 detected (" + javaVersion + ") disabling url caching to avoid memory leak."); |
|
581 |
logger.info("jdk8 memory leak fix: jdk8 detected (" + javaVersion + ") disabling url caching to avoid memory leak.");
|
|
581 | 582 |
org.eclipse.jetty.util.resource.Resource.setDefaultUseCaches(false); |
582 | 583 |
File tmpio = new File(System.getProperty("java.io.tmpdir")); |
583 | 584 |
tmpio.toURI().toURL().openConnection().setDefaultUseCaches(false); |
585 |
} else { |
|
586 |
logger.info("jdk8 memory leak fix: unaffected jdk " + javaVersion + " detected"); |
|
587 |
} |
|
588 |
} |
|
589 |
|
|
590 |
private void jdk8MemleakFixInstance(ClassLoader classLoader, CdmInstance instance) throws IOException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { |
|
591 |
String javaVersion = System.getProperty("java.version"); |
|
592 |
if(javaVersion.startsWith("1.8")){ |
|
593 |
logger.info("jdk8 memory leak fix for " + instance.getName() + ": jdk8 detected (" + javaVersion + ") disabling url caching to avoid memory leak."); |
|
594 |
Class<?> fileClass = classLoader.loadClass("java.io.File"); |
|
595 |
File tmpio = (File) fileClass.getConstructor(String.class).newInstance("java.io.tmpdir"); |
|
596 |
tmpio.toURI().toURL().openConnection().setDefaultUseCaches(false); |
|
597 |
} else { |
|
598 |
logger.info("jdk8 memory leak fix, " + instance.getName() + "unaffected jdk " + javaVersion + " detected"); |
|
584 | 599 |
} |
585 | 600 |
} |
586 | 601 |
|
... | ... | |
749 | 764 |
if(webAppClassPath != null){ |
750 | 765 |
logger.info("Running cdm-webapp from source folder: Adding class path supplied by option '-" + WEBAPP_CLASSPATH.getOpt() +" =" + webAppClassPath +"' to WebAppClassLoader"); |
751 | 766 |
classLoader.addClassPath(webAppClassPath); |
767 |
try { |
|
768 |
jdk8MemleakFixInstance(classLoader, instance); |
|
769 |
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
770 |
| IllegalArgumentException | InvocationTargetException | NoSuchMethodException |
|
771 |
| SecurityException e) { |
|
772 |
logger.error("Cannot apply jdk8MemleakFix to instance " + instance, e); |
|
773 |
} |
|
752 | 774 |
} else { |
753 | 775 |
throw new RuntimeException("Classpath cdm-webapp for missing while running cdm-webapp from source folder. Please supplied cdm-server option '-" + WEBAPP_CLASSPATH.getOpt() +""); |
754 | 776 |
} |
Also available in: Unified diff
ref #5048 disabling url caching per instance for jdk1.8 to avoid memleak