From: schultz Date: Tue, 20 Sep 2011 20:17:23 +0000 (+0000) Subject: Fixed bug #51687: Improve JreMemoryLeakPreventionListener against leak caused by... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6b6376d940b4ddca0b98dfccdef817c8f367f671;p=tomcat7.0 Fixed bug #51687: Improve JreMemoryLeakPreventionListener against leak caused by sun.java2d.Disposer - Added (optional) protection against sun.java2d.Disposer thread pinning a WebappClassLoader into memory in the JreMemoryLeakPreventionListener. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1173333 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index 37b13e8ca..3223154f4 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -81,6 +81,19 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { } /** + * Protect against the memory leak caused when the + * sun.java2d.Disposer class is loaded by a web application. + * Defaults to false because a new Thread is launched. + */ + private boolean java2dDisposerProtection = false; + public boolean isJava2DDisposerProtection() { + return java2dDisposerProtection; + } + public void setJava2DDisposerProtection(boolean java2dDisposerProtection) { + this.java2dDisposerProtection = java2dDisposerProtection; + } + + /** * Protect against the memory leak caused when the first call to * sun.misc.GC.requestLatency(long) is triggered by a web * application. This first call will start a GC Daemon thread with the @@ -237,6 +250,18 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { java.awt.Toolkit.getDefaultToolkit(); } + // Trigger the creation of the "Java2D Disposer" thread. + // See https://issues.apache.org/bugzilla/show_bug.cgi?id=51687 + if(java2dDisposerProtection) { + try { + Class.forName("sun.java2d.Disposer"); + } + catch (ClassNotFoundException cnfe) { + // Ignore this case: we must be running on a + // non-Sun-based JRE. + } + } + /* * Several components end up calling: * sun.misc.GC.requestLatency(long) diff --git a/webapps/docs/config/listeners.xml b/webapps/docs/config/listeners.xml index 1900e7b99..7044eff49 100644 --- a/webapps/docs/config/listeners.xml +++ b/webapps/docs/config/listeners.xml @@ -199,6 +199,13 @@ startup on non-Sun JVMs. The default is true.

+ +

Enables protection so that loading the + sun.java2d.Disposer class by a web application does not + result in a memory leak. + Defaults to false because a thread is launched.

+
+

Enables protection so that the PoolCleaner thread started by com.sun.jndi.ldap.LdapPoolManager does not result in a