Author: slaurent Date: Thu Sep 22 20:01:52 2011 New Revision: 1174353 URL: http://svn.apache.org/viewvc?rev=1174353&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/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=1174353&r1=1174352&r2=1174353&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Thu Sep 22 20:01:52 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/trunk/java/org/apache/catalina/core/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1174353&r1=1174352&r2=1174353&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Thu Sep 22 20:01:52 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/trunk/webapps/docs/config/listeners.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=1174353&r1=1174352&r2=1174353&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/listeners.xml (original) +++ tomcat/trunk/webapps/docs/config/listeners.xml Thu Sep 22 20:01:52 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