From cebdc3cc5d0d25e2bc31386b98e839c0297da7fe Mon Sep 17 00:00:00 2001 From: kkolinko Date: Wed, 24 Aug 2011 22:25:03 +0000 Subject: [PATCH] Forward-port r1159673 and r1159680 from tc7.0.x Fixes http://issues.apache.org/bugzilla/show_bug.cgi?id=51688 JreMemoryLeakPreventionListener now protects against AWT thread creation. (schultz) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1161303 13f79535-47bb-0310-9956-ffa450edef68 --- .../core/JreMemoryLeakPreventionListener.java | 22 ++++++++++++++++++++-- webapps/docs/config/listeners.xml | 7 +++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index 91d11d2d0..37b13e8ca 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -67,7 +67,19 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { public void setAppContextProtection(boolean appContextProtection) { this.appContextProtection = appContextProtection; } - + + /** + * Protect against the memory leak caused when the first call to + * java.awt.Toolkit.getDefaultToolkit() is triggered + * by a web application. Defaults to false because a new + * Thread is launched. + */ + private boolean awtThreadProtection = false; + public boolean isAWTThreadProtection() { return awtThreadProtection; } + public void setAWTThreadProtection(boolean awtThreadProtection) { + this.awtThreadProtection = awtThreadProtection; + } + /** * Protect against the memory leak caused when the first call to * sun.misc.GC.requestLatency(long) is triggered by a web @@ -218,7 +230,13 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { if (appContextProtection) { ImageIO.getCacheDirectory(); } - + + // Trigger the creation of the AWT (AWT-Windows, AWT-XAWT, + // etc.) thread + if (awtThreadProtection) { + java.awt.Toolkit.getDefaultToolkit(); + } + /* * 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 8d148e4a9..1900e7b99 100644 --- a/webapps/docs/config/listeners.xml +++ b/webapps/docs/config/listeners.xml @@ -174,6 +174,13 @@ is true.

+ +

Enables protection so that calls to + java.awt.Toolkit.getDefaultToolkit() triggered by a web + application do not result in a memory leak. + Defaults to false because an AWT thread is launched.

+
+

The first use of java.sql.DriverManager will trigger the loading of JDBNC Driver in the the current class loader. The web -- 2.11.0