tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r884341 - in /tomcat/trunk: java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java java/org/apache/catalina/core/LocalStrings.properties webapps/docs/config/listeners.xml
Date Wed, 25 Nov 2009 23:56:31 GMT
Author: markt
Date: Wed Nov 25 23:56:30 2009
New Revision: 884341

URL: http://svn.apache.org/viewvc?rev=884341&view=rev
Log:
More memory leak protection. This one is particularly nasty as profilers don't appear to show
the GC root associated with the leak.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    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=884341&r1=884340&r2=884341&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Wed Nov
25 23:56:30 2009
@@ -23,6 +23,8 @@
 import java.net.URLConnection;
 
 import javax.imageio.ImageIO;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleEvent;
@@ -75,6 +77,17 @@
         this.urlCacheProtection = urlCacheProtection;
     }
 
+    /**
+     * XML parsing can pin a web application class loader in memory. This is
+     * particularly nasty as profilers (at least YourKit and Eclispe MAT) don't
+     * idenitfy any GC roots related to this. 
+     */
+    protected boolean xmlParsingProtection = true;
+    public boolean isXmlParsingProtection() { return xmlParsingProtection; }
+    public void setXmlParsingProtection(boolean xmlParsingProtection) {
+        this.xmlParsingProtection = xmlParsingProtection;
+    }
+    
     @Override
     public void lifecycleEvent(LifecycleEvent event) {
         // Initialise these classes when Tomcat starts
@@ -122,7 +135,23 @@
                             "jreLeakListener.jarUrlConnCacheFail"), e);
                 } catch (IOException e) {
                     log.error(sm.getString(
-                    "jreLeakListener.jarUrlConnCacheFail"), e);
+                            "jreLeakListener.jarUrlConnCacheFail"), e);
+                }
+            }
+            
+            /*
+             * Haven't got to the root of what is going on with this leak but if
+             * a web app is the first to make the calls below the web
+             * application class loader will be pinned in memory.
+             */
+            if (xmlParsingProtection) {
+                DocumentBuilderFactory factory =
+                    DocumentBuilderFactory.newInstance();
+                try {
+                    factory.newDocumentBuilder();
+                } catch (ParserConfigurationException e) {
+                    log.error(sm.getString(
+                            "jreLeakListener.xmlParseFail"), e);
                 }
             }
         }

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=884341&r1=884340&r2=884341&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Wed Nov 25 23:56:30
2009
@@ -66,6 +66,7 @@
 interceptorValve.alreadyStarted=InterceptorValve has already been started
 interceptorValve.notStarted=InterceptorValve has not yet been started
 jreLeakListener.jarUrlConnCacheFail=Failed to disable Jar URL connection caching by default
+jreLeakListener.xmlParseFail=Error whilst attempting to prevent memory leaks during XML parsing
 naming.wsdlFailed=Failed to find wsdl file: {0}
 naming.bindFailed=Failed to bind object: {0}
 naming.jmxRegistrationFailed=Failed to register in JMX: {0}

Modified: tomcat/trunk/webapps/docs/config/listeners.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=884341&r1=884340&r2=884341&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/listeners.xml (original)
+++ tomcat/trunk/webapps/docs/config/listeners.xml Wed Nov 25 23:56:30 2009
@@ -256,6 +256,13 @@
         case by case basis as required. Defaults to <code>true</code>.</p>
       </attribute>
 
+      <attribute name="xmlParsingProtection" required="false">
+        <p>Enables protection so that parsing XML files within a web application
+        does not result in a memopry leak. Note that memory profilers may not
+        display the GC root associated with this leak making it particularly
+        hard to diagnose. Defaults to <code>true</code>.</p>
+      </attribute>
+
     </attributes>
 
   </subsection>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message