Author: markt Date: Tue May 15 10:26:30 2018 New Revision: 1831618 URL: http://svn.apache.org/viewvc?rev=1831618&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=50175 Add a new attribute to the standard context implementation, skipMemoryLeakChecksOnJvmShutdown, that allows the user to configure Tomcat to skip the memory leak checks usually performed during web application stop if that stop is triggered by a JVM shutdown.
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java tomcat/trunk/webapps/docs/changelog.xml tomcat/trunk/webapps/docs/config/context.xml Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1831618&r1=1831617&r2=1831618&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue May 15 10:26:30 2018 @@ -743,6 +743,12 @@ public class StandardContext extends Con private boolean clearReferencesObjectStreamClassCaches = true; /** + * Should Tomcat skip the memory leak checks when the web application is + * stopped as part of the process of shutting down the JVM? + */ + private boolean skipMemoryLeakChecksOnJvmShutdown = false; + + /** * Should the effective web.xml be logged when the context starts? */ private boolean logEffectiveWebXml = false; @@ -2691,6 +2697,16 @@ public class StandardContext extends Con } + public boolean getSkipMemoryLeakChecksOnJvmShutdown() { + return skipMemoryLeakChecksOnJvmShutdown; + } + + + public void setSkipMemoryLeakChecksOnJvmShutdown(boolean skipMemoryLeakChecksOnJvmShutdown) { + this.skipMemoryLeakChecksOnJvmShutdown = skipMemoryLeakChecksOnJvmShutdown; + } + + public Boolean getFailCtxIfServletStartFails() { return failCtxIfServletStartFails; } @@ -4951,6 +4967,8 @@ public class StandardContext extends Con getClearReferencesHttpClientKeepAliveThread()); setClassLoaderProperty("clearReferencesObjectStreamClassCaches", getClearReferencesObjectStreamClassCaches()); + setClassLoaderProperty("skipMemoryLeakChecksOnJvmShutdown", + getSkipMemoryLeakChecksOnJvmShutdown()); // By calling unbindThread and bindThread in a row, we setup the // current Thread CCL to be the webapp classloader Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1831618&r1=1831617&r2=1831618&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java Tue May 15 10:26:30 2018 @@ -368,6 +368,12 @@ public abstract class WebappClassLoaderB private boolean clearReferencesObjectStreamClassCaches = true; /** + * Should Tomcat skip the memory leak checks when the web application is + * stopped as part of the process of shutting down the JVM? + */ + private boolean skipMemoryLeakChecksOnJvmShutdown = false; + + /** * Holds the class file transformers decorating this class loader. The * CopyOnWriteArrayList is thread safe. It is expensive on writes, but * those should be rare. It is very fast on reads, since synchronization @@ -613,6 +619,16 @@ public abstract class WebappClassLoaderB } + public boolean getSkipMemoryLeakChecksOnJvmShutdown() { + return skipMemoryLeakChecksOnJvmShutdown; + } + + + public void setSkipMemoryLeakChecksOnJvmShutdown(boolean skipMemoryLeakChecksOnJvmShutdown) { + this.skipMemoryLeakChecksOnJvmShutdown = skipMemoryLeakChecksOnJvmShutdown; + } + + // ------------------------------------------------------- Reloader Methods /** @@ -1524,6 +1540,21 @@ public abstract class WebappClassLoaderB */ protected void clearReferences() { + // If the JVM is shutting down, skip the memory leak checks + if (skipMemoryLeakChecksOnJvmShutdown + && !resources.getContext().getParent().getState().isAvailable()) { + // During reloading / redeployment the parent is expected to be + // available. Parent is not available so this might be a JVM + // shutdown. + try { + Thread dummyHook = new Thread(); + Runtime.getRuntime().addShutdownHook(dummyHook); + Runtime.getRuntime().removeShutdownHook(dummyHook); + } catch (IllegalStateException ise) { + return; + } + } + // De-register any remaining JDBC drivers clearReferencesJdbc(); Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1831618&r1=1831617&r2=1831618&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue May 15 10:26:30 2018 @@ -85,6 +85,13 @@ Add the <code>AuthenticatedUserRealm</code> for use with CLIENT-CERT and SPNEGO when just the authenticated user name is required. (markt) </add> + <fix> + <bug>50175</bug>: Add a new attribute to the standard context + implementation, <code>skipMemoryLeakChecksOnJvmShutdown</code>, that + allows the user to configure Tomcat to skip the memory leak checks + usually performed during web application stop if that stop is triggered + by a JVM shutdown. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> Modified: tomcat/trunk/webapps/docs/config/context.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/context.xml?rev=1831618&r1=1831617&r2=1831618&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/config/context.xml (original) +++ tomcat/trunk/webapps/docs/config/context.xml Tue May 15 10:26:30 2018 @@ -811,6 +811,13 @@ default value of <code>true</code> will be used.</p> </attribute> + <attribute name="skipMemoryLeakChecksOnJvmShutdown" required="false"> + <p>If <code>true</code>, Tomcat will not perform the usual memory leak + checks when the web applicaiton is stopped if that web application is + stopped as part of a JVM shutdown. If not specified, the default value + of <code>false</code> will be used.</p> + </attribute> + <attribute name="unloadDelay" required="false"> <p>Number of ms that the container will wait for servlets to unload. If not specified, the default value is <code>2000</code> ms.</p> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org