Author: markt Date: Sat Oct 13 18:01:41 2018 New Revision: 1843770 URL: http://svn.apache.org/viewvc?rev=1843770&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62802 Restore the appContextProtection attribute to the JreMemoryLeakPreventionListener as application code may still trigger this memory leak.
Modified: tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java tomcat/trunk/webapps/docs/changelog.xml tomcat/trunk/webapps/docs/config/listeners.xml Modified: tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java?rev=1843770&r1=1843769&r2=1843770&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Sat Oct 13 18:01:41 2018 @@ -25,6 +25,7 @@ import java.sql.DriverManager; import java.util.StringTokenizer; import java.util.concurrent.ForkJoinPool; +import javax.imageio.ImageIO; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -67,6 +68,18 @@ public class JreMemoryLeakPreventionList "java.util.concurrent.ForkJoinPool.common.threadFactory"; /** * Protect against the memory leak caused when the first call to + * <code>sun.awt.AppContext.getAppContext()</code> is triggered by a web + * application. Defaults to <code>false</code> since Tomcat code no longer + * triggers this althoguh application code may. + */ + private boolean appContextProtection = false; + public boolean isAppContextProtection() { return appContextProtection; } + public void setAppContextProtection(boolean appContextProtection) { + this.appContextProtection = appContextProtection; + } + + /** + * Protect against the memory leak caused when the first call to * <code>java.awt.Toolkit.getDefaultToolkit()</code> is triggered * by a web application. Defaults to <code>false</code> because a new * Thread is launched. @@ -221,6 +234,28 @@ public class JreMemoryLeakPreventionList Thread.currentThread().setContextClassLoader( ClassLoader.getSystemClassLoader()); + /* + * Several components end up calling: + * sun.awt.AppContext.getAppContext() + * + * Those libraries / components known to trigger memory leaks + * due to eventual calls to getAppContext() are: + * - Google Web Toolkit via its use of javax.imageio + * - Batik + * - others TBD + * + * Note tha a call to sun.awt.AppContext.getAppContext() results + * in a thread being started named AWT-AppKit that requires a + * graphical environment to be available. + */ + + // Trigger a call to sun.awt.AppContext.getAppContext(). This + // will pin the system class loader in memory but that shouldn't + // be an issue. + if (appContextProtection) { + ImageIO.getCacheDirectory(); + } + // Trigger the creation of the AWT (AWT-Windows, AWT-XAWT, // etc.) thread. // Note this issue is fixed in Java 8 update 05 onwards. Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1843770&r1=1843769&r2=1843770&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Sat Oct 13 18:01:41 2018 @@ -100,6 +100,11 @@ <bug>62797</bug>: Pass throwable to keep client aborts with status 200 rather than 500. Patch submitted by zikfat. (remm) </fix> + <fix> + <bug>62802</bug>: Restore the <code>appContextProtection</code> + attribute to the <code>JreMemoryLeakPreventionListener</code> as + application code may still trigger this memory leak. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> Modified: tomcat/trunk/webapps/docs/config/listeners.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=1843770&r1=1843769&r2=1843770&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/listeners.xml (original) +++ tomcat/trunk/webapps/docs/config/listeners.xml Sat Oct 13 18:01:41 2018 @@ -178,6 +178,15 @@ <attributes> + <attribute name="appContextProtection" required="false"> + <p>Enables protection so that calls to + <code>sun.awt.AppContext.getAppContext()</code> triggered by a web + application do not result in a memory leak. Note that enabling this + protection will trigger a requirement for a graphical environment unless + Java is started in head-less mode. The default is <code>false</code>. + </p> + </attribute> + <attribute name="AWTThreadProtection" required="false"> <p>Enables protection so that calls to <code>java.awt.Toolkit.getDefaultToolkit()</code> triggered by a web --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org