From: slaurent Date: Thu, 22 Sep 2011 20:01:52 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51862 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ab3b9cd3f655a68fcefe184894942e8188bd914f;p=tomcat7.0 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 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1174353 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index 3223154f4..22b0a4835 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -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 JreMemoryLeakPreventionListener implements LifecycleListener { 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 JreMemoryLeakPreventionListener implements LifecycleListener { } } } + + 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); diff --git a/java/org/apache/catalina/core/LocalStrings.properties b/java/org/apache/catalina/core/LocalStrings.properties index 558152395..839005c83 100644 --- a/java/org/apache/catalina/core/LocalStrings.properties +++ b/java/org/apache/catalina/core/LocalStrings.properties @@ -83,6 +83,7 @@ jreLeakListener.jarUrlConnCacheFail=Failed to disable Jar URL connection caching 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} diff --git a/webapps/docs/config/listeners.xml b/webapps/docs/config/listeners.xml index 7044eff49..ef29c3cac 100644 --- a/webapps/docs/config/listeners.xml +++ b/webapps/docs/config/listeners.xml @@ -181,6 +181,16 @@ Defaults to false because an AWT thread is launched.

+ +

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 + oracle.jdbc.driver.OracleTimeoutThreadPerVM. + The default value is empty, but specific JRE classes are loaded by other leak + protection features managed by other attributes of this Listener.

+
+

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