Author: markt
Date: Wed Aug 10 13:42:20 2011
New Revision: 1156182
URL: http://svn.apache.org/viewvc?rev=1156182&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51640
Improve the memory leak prevention for leaks triggered by
java.sql.DriverManager.
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/webapps/docs/changelog.xml
tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
svn:mergeinfo = /tomcat/trunk:1156171
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=1156182&r1=1156181&r2=1156182&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
Wed Aug 10 13:42:20 2011
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
+import java.sql.DriverManager;
import javax.imageio.ImageIO;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -150,8 +151,8 @@ public class JreMemoryLeakPreventionList
}
/**
- * <code>com.sun.jndi.ldap.LdapPoolManager</code> class spawns a thread
when it
- * is initialized if the system property
+ * <code>com.sun.jndi.ldap.LdapPoolManager</code> class spawns a thread
when
+ * it is initialized if the system property
* <code>com.sun.jndi.ldap.connect.pool.timeout</code> is greater than 0.
* That thread inherits the context class loader of the current thread, so
* that there may be a web application class loader leak if the web app
@@ -162,7 +163,21 @@ public class JreMemoryLeakPreventionList
public void setLdapPoolProtection(boolean ldapPoolProtection) {
this.ldapPoolProtection = ldapPoolProtection;
}
-
+
+ /**
+ * The first access to {@link DriverManager} will trigger the loading of
+ * all {@link java.sql.Driver}s in the the current class loader. The web
+ * application level memory leak protection can take care of this in most
+ * cases but triggering the loading here has fewer side-effects.
+ */
+ private boolean driverManagerProtection = true;
+ public boolean isDriverManagerProtection() {
+ return driverManagerProtection;
+ }
+ public void setDriverManagerProtection(boolean driverManagerProtection) {
+ this.driverManagerProtection = driverManagerProtection;
+ }
+
@Override
public void lifecycleEvent(LifecycleEvent event) {
// Initialise these classes when Tomcat starts
@@ -178,6 +193,14 @@ public class JreMemoryLeakPreventionList
ClassLoader.getSystemClassLoader());
/*
+ * First call to this loads all drivers in the current class
+ * loader
+ */
+ if (driverManagerProtection) {
+ DriverManager.getDrivers();
+ }
+
+ /*
* Several components end up calling:
* sun.awt.AppContext.getAppContext()
*
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1156182&r1=1156181&r2=1156182&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Aug 10 13:42:20 2011
@@ -54,6 +54,14 @@
issues to not "pop up" wrt. others).
-->
<section name="Tomcat 7.0.21 (markt)">
+ <subsection name="Catalina">
+ <changelog>
+ <add>
+ <bug>51640</bug>: Improve the memory leak prevention for leaks
triggered
+ by java.sql.DriverManager. (markt)
+ </add>
+ </changelog>
+ </subsection>
<subsection name="Coyote">
<changelog>
<bug>51641</bug>: Use correct key when removing processor instances from
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=1156182&r1=1156181&r2=1156182&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/listeners.xml Wed Aug 10 13:42:20
2011
@@ -174,6 +174,14 @@
is <code>true</code>.</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
+ application level memory leak protection can take care of this in most
+ cases but triggering the loading here has fewer side-effects. The
+ default is <code>true</code></p>
+ </attribute>
+
<attribute name="gcDaemonProtection" required="false">
<p>Enables protection so that calls to
<code>sun.misc.GC.requestLatency(long)</code> triggered by a web
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]