Author: markt Date: Mon Sep 3 09:24:24 2018 New Revision: 1839922 URL: http://svn.apache.org/viewvc?rev=1839922&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62670 Adjust the memory leak protection for the DriverManager so that JDBC drivers located in $CATALINA_HOME/lib and $CATALINA_BASE/lib are loaded via the service loader mechanism when the protection is enabled.
Modified: tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java tomcat/trunk/webapps/docs/changelog.xml tomcat/trunk/webapps/docs/config/listeners.xml tomcat/trunk/webapps/docs/jndi-datasource-examples-howto.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=1839922&r1=1839921&r2=1839922&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Mon Sep 3 09:24:24 2018 @@ -197,6 +197,21 @@ public class JreMemoryLeakPreventionList // Initialise these classes when Tomcat starts if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { + /* + * First call to this loads all drivers visible to the current class + * loader and its parents. + * + * Note: This is called before the context class loader is changed + * because we want any drivers located in CATALINA_HOME/lib + * and/or CATALINA_HOME/lib to be visible to DriverManager. + * Users wishing to avoid having JDBC drivers loaded by this + * class loader should add the JDBC driver(s) to the class + * path so they are loaded by the system class loader. + */ + if (driverManagerProtection) { + DriverManager.getDrivers(); + } + ClassLoader loader = Thread.currentThread().getContextClassLoader(); try @@ -206,14 +221,6 @@ public class JreMemoryLeakPreventionList Thread.currentThread().setContextClassLoader( ClassLoader.getSystemClassLoader()); - /* - * First call to this loads all drivers in the current class - * loader - */ - if (driverManagerProtection) { - DriverManager.getDrivers(); - } - // Trigger the creation of the AWT (AWT-Windows, AWT-XAWT, // etc.) thread. // Note this issue is fixed in Java 8 update 05 onwards. Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1839922&r1=1839921&r2=1839922&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Sep 3 09:24:24 2018 @@ -57,6 +57,13 @@ <code>@MultipartConfig</code> annotation regardless of HTTP method. (markt) </fix> + <fix> + <bug>62670</bug>: Adjust the memory leak protection for the + <code>DriverManager</code> so that JDBC drivers located in + <code>$CATALINA_HOME/lib</code> and <code>$CATALINA_BASE/lib</code> are + loaded via the service loader mechanism when the protection is enabled. + (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> Modified: tomcat/trunk/webapps/docs/config/listeners.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=1839922&r1=1839921&r2=1839922&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/listeners.xml (original) +++ tomcat/trunk/webapps/docs/config/listeners.xml Mon Sep 3 09:24:24 2018 @@ -199,10 +199,10 @@ <attribute name="driverManagerProtection" required="false"> <p>The first use of <code>java.sql.DriverManager</code> will trigger the - loading of JDBC Driver in 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> + loading of JDBC Drivers visible to the current class loader and its + parents. 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="forkJoinCommonPoolProtection" required="false"> Modified: tomcat/trunk/webapps/docs/jndi-datasource-examples-howto.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/jndi-datasource-examples-howto.xml?rev=1839922&r1=1839921&r2=1839922&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/jndi-datasource-examples-howto.xml (original) +++ tomcat/trunk/webapps/docs/jndi-datasource-examples-howto.xml Mon Sep 3 09:24:24 2018 @@ -83,14 +83,17 @@ a servlet container environment. The pro <code>java.sql.DriverManager</code> will scan for the drivers only once.</p> <p>The <a href="config/listeners.html">JRE Memory Leak Prevention Listener</a> -that is included with Apache Tomcat solves this by triggering the drivers scan +that is included with Apache Tomcat solves this by triggering the driver scan during Tomcat startup. This is enabled by default. It means that only -libraries visible to the listener such as the ones in -<code>$CATALINA_BASE/lib</code> will be scanned for database drivers. -If you are considering disabling this feature, note that -the scan would be triggered by the first web application that is -using JDBC, leading to failures when this web application is reloaded -and for other web applications that rely on this feature. +libraries visible to the common class loader and its parents will be scanned for +database drivers. This include drivers in <code>$CATALINA_HOME/lib</code>, +<code>$CATALINA_BASE/lib</code>, the class path and (where the JRE supports it) +the endorsed directory. Drivers packaged in web applications (in +<code>WEB-INF/lib</code>) and in the shared class loader (where configured) will +not be visible and will not be loaded automatically. If you are considering +disabling this feature, note that the scan would be triggered by the first web +application that is using JDBC, leading to failures when this web application is +reloaded and for other web applications that rely on this feature. </p> <p>Thus, the web applications that have database drivers in their --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org