Author: slaurent Date: Thu Sep 22 20:06:58 2011 New Revision: 1174359 URL: http://svn.apache.org/viewvc?rev=1174359&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51862 bug 51862: JreMemoryLeakPreventionListener enhancement to load configurable classes https://issues.apache.org/bugzilla/show_bug.cgi?id=51862
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Sep 22 20:06:58 2011 @@ -1 +1 @@ -/tomcat/trunk:1156171,1156276,1156304,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166752,1166757,1167368,1167394,1169447,1170647,1171692,1172233-1172234,1172236,1172269,1172278,1172282,1172610,1172664,1172689,1172711,1173020-1173021,1173082,1173088,1173090,1173096,1173241,1173256,1173288,1173461 ,1173614,1173630,1173659,1173722,1174061,1174239 +/tomcat/trunk:1156171,1156276,1156304,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166752,1166757,1167368,1167394,1169447,1170647,1171692,1172233-1172234,1172236,1172269,1172278,1172282,1172610,1172664,1172689,1172711,1173020-1173021,1173082,1173088,1173090,1173096,1173241,1173256,1173288,1173461 ,1173614,1173630,1173659,1173722,1174061,1174239,1174353 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java?rev=1174359&r1=1174358&r2=1174359&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Thu Sep 22 20:06:58 2011 @@ -24,6 +24,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.sql.DriverManager; +import java.util.StringTokenizer; import javax.imageio.ImageIO; import javax.xml.parsers.DocumentBuilderFactory; @@ -202,7 +203,21 @@ public class JreMemoryLeakPreventionList public void setDriverManagerProtection(boolean driverManagerProtection) { this.driverManagerProtection = driverManagerProtection; } - + + /** + * List of comma-separated fully qualified class names to load and initialize during + * the startup of this Listener. This allows to pre-load classes that are known to + * provoke classloader leaks if they are loaded during a request processing. + */ + private String classesToInitialize = null; + public String getClassesToInitialize() { + return classesToInitialize; + } + public void setClassesToInitialize(String classesToInitialize) { + this.classesToInitialize = classesToInitialize; + } + + @Override public void lifecycleEvent(LifecycleEvent event) { // Initialise these classes when Tomcat starts @@ -419,6 +434,22 @@ public class JreMemoryLeakPreventionList } } } + + if (classesToInitialize != null) { + StringTokenizer strTok = + new StringTokenizer(classesToInitialize, ", \r\n\t"); + while (strTok.hasMoreTokens()) { + String classNameToLoad = strTok.nextToken(); + try { + Class.forName(classNameToLoad); + } catch (ClassNotFoundException e) { + log.error( + sm.getString("jreLeakListener.classToInitializeFail", + classNameToLoad), e); + // continue with next class to load + } + } + } } finally { Thread.currentThread().setContextClassLoader(loader); Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1174359&r1=1174358&r2=1174359&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties Thu Sep 22 20:06:58 2011 @@ -83,6 +83,7 @@ jreLeakListener.jarUrlConnCacheFail=Fail jreLeakListener.xmlParseFail=Error whilst attempting to prevent memory leaks during XML parsing jreLeakListener.authPolicyFail=Error whilst attempting to prevent memory leak in javax.security.auth.Policy class jreLeakListener.ldapPoolManagerFail=Failed to trigger creation of the com.sun.jndi.ldap.LdapPoolManager class during Tomcat start to prevent possible memory leaks. This is expected on non-Sun JVMs. +jreLeakListener.classToInitializeFail=Failed to load class {0} during Tomcat start to prevent possible memory leaks. 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/tc7.0.x/trunk/webapps/docs/config/listeners.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml?rev=1174359&r1=1174358&r2=1174359&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml Thu Sep 22 20:06:58 2011 @@ -181,6 +181,16 @@ Defaults to <code>false</code> because an AWT thread is launched.</p> </attribute> + <attribute name="classesToInitialize" required="false"> + <p>List of comma-separated fully qualified class names to load and initialize + during the startup of this Listener. This allows to pre-load classes that are + known to provoke classloader leaks if they are loaded during a request + processing. Non-JRE classes may be referenced, like + <code>oracle.jdbc.driver.OracleTimeoutThreadPerVM</code>. + The default value is empty, but specific JRE classes are loaded by other leak + protection features managed by other attributes of this Listener.</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 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org