Forward-port r1159673 and r1159680 from tc7.0.x
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 24 Aug 2011 22:25:03 +0000 (22:25 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 24 Aug 2011 22:25:03 +0000 (22:25 +0000)
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

java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
webapps/docs/config/listeners.xml

index 91d11d2..37b13e8 100644 (file)
@@ -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
+     * <code>java.awt.Toolkit.getDefaultToolkit()</code> is triggered
+     * by a web application. Defaults to <code>false</code> 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
      * <code>sun.misc.GC.requestLatency(long)</code> 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)
index 8d148e4..1900e7b 100644 (file)
         is <code>true</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
+        application do not result in a memory leak.
+        Defaults to <code>false</code> because an AWT thread is launched.</p>
+      </attribute>
+
       <attribute name="driverManagerProtection" required="false">
         <p>The first use of <code>java.sql.DriverManager</code> will trigger the
         loading of JDBNC Driver in the the current class loader. The web