From d43e4df80bfa46de52034aab18d725bf8805df43 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 1 Jun 2010 16:59:14 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48971 Make stopping of TimerThreads optional and disabled by default git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@950164 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/core/StandardContext.java | 34 ++++++++++++- .../apache/catalina/loader/WebappClassLoader.java | 57 +++++++++++++++------- java/org/apache/catalina/loader/WebappLoader.java | 2 + webapps/docs/config/context.xml | 8 +++ 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 9b393d885..0e0ec5eca 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -759,9 +759,16 @@ public class StandardContext extends ContainerBase * instability. As such, enabling this should be viewed as an option of last * resort in a development environment and is not recommended in a * production environment. If not specified, the default value of - * false will be used. + * false will be used. */ private boolean clearReferencesStopThreads = false; + + /** + * Should Tomcat attempt to terminate any {@link java.util.TimerThread}s + * that have been started by the web application? If not specified, the + * default value of false will be used. + */ + private boolean clearReferencesStopTimerThreads = false; /** * Should Tomcat attempt to clear any ThreadLocal objects that are instances @@ -2309,6 +2316,31 @@ public class StandardContext extends ContainerBase /** + * Return the clearReferencesStopTimerThreads flag for this Context. + */ + public boolean getClearReferencesStopTimerThreads() { + return (this.clearReferencesStopTimerThreads); + } + + + /** + * Set the clearReferencesStopTimerThreads feature for this Context. + * + * @param clearReferencesStopTimerThreads The new flag value + */ + public void setClearReferencesStopTimerThreads( + boolean clearReferencesStopTimerThreads) { + + boolean oldClearReferencesStopTimerThreads = + this.clearReferencesStopTimerThreads; + this.clearReferencesStopTimerThreads = clearReferencesStopTimerThreads; + support.firePropertyChange("clearReferencesStopTimerThreads", + oldClearReferencesStopTimerThreads, + this.clearReferencesStopTimerThreads); + } + + + /** * Return the clearReferencesThreadLocals flag for this Context. */ public boolean getClearReferencesThreadLocals() { diff --git a/java/org/apache/catalina/loader/WebappClassLoader.java b/java/org/apache/catalina/loader/WebappClassLoader.java index 561b2e6d0..74388df4c 100644 --- a/java/org/apache/catalina/loader/WebappClassLoader.java +++ b/java/org/apache/catalina/loader/WebappClassLoader.java @@ -444,13 +444,18 @@ public class WebappClassLoader * instability. As such, enabling this should be viewed as an option of last * resort in a development environment and is not recommended in a * production environment. If not specified, the default value of - * false will be used. Note that instances of - * java.util.TimerThread will always be terminate since a safe method exists - * to do so. + * false will be used. */ private boolean clearReferencesStopThreads = false; /** + * Should Tomcat attempt to terminate any {@link java.util.TimerThread}s + * that have been started by the web application? If not specified, the + * default value of false will be used. + */ + private boolean clearReferencesStopTimerThreads = false; + + /** * Should Tomcat attempt to clear any ThreadLocal objects that are instances * of classes loaded by this class loader. Failure to remove any such * objects will result in a memory leak on web application stop, undeploy or @@ -707,6 +712,25 @@ public class WebappClassLoader /** + * Return the clearReferencesStopTimerThreads flag for this Context. + */ + public boolean getClearReferencesStopTimerThreads() { + return (this.clearReferencesStopTimerThreads); + } + + + /** + * Set the clearReferencesStopTimerThreads feature for this Context. + * + * @param clearReferencesStopTimerThreads The new flag value + */ + public void setClearReferencesStopTimerThreads( + boolean clearReferencesStopTimerThreads) { + this.clearReferencesStopTimerThreads = clearReferencesStopTimerThreads; + } + + + /** * Return the clearReferencesLogFactoryRelease flag for this Context. */ public boolean getClearReferencesLogFactoryRelease() { @@ -714,6 +738,16 @@ public class WebappClassLoader } + /** + * Set the clearReferencesLogFactoryRelease feature for this Context. + * + * @param clearReferencesLogFactoryRelease The new flag value + */ + public void setClearReferencesLogFactoryRelease( + boolean clearReferencesLogFactoryRelease) { + this.clearReferencesLogFactoryRelease = + clearReferencesLogFactoryRelease; + } /** @@ -735,18 +769,6 @@ public class WebappClassLoader } - /** - * Set the clearReferencesLogFactoryRelease feature for this Context. - * - * @param clearReferencesLogFactoryRelease The new flag value - */ - public void setClearReferencesLogFactoryRelease( - boolean clearReferencesLogFactoryRelease) { - this.clearReferencesLogFactoryRelease = - clearReferencesLogFactoryRelease; - } - - // ------------------------------------------------------- Reloader Methods @@ -2152,9 +2174,10 @@ public class WebappClassLoader continue; } - // TimerThread is not normally visible + // TimerThread can be stopped safely so treat separately if (thread.getClass().getName().equals( - "java.util.TimerThread")) { + "java.util.TimerThread") && + clearReferencesStopTimerThreads) { clearReferencesStopTimerThread(thread); continue; } diff --git a/java/org/apache/catalina/loader/WebappLoader.java b/java/org/apache/catalina/loader/WebappLoader.java index 3d40a13a6..8ca465402 100644 --- a/java/org/apache/catalina/loader/WebappLoader.java +++ b/java/org/apache/catalina/loader/WebappLoader.java @@ -576,6 +576,8 @@ public class WebappLoader extends LifecycleMBeanBase ((StandardContext) container).getClearReferencesStatic()); classLoader.setClearReferencesStopThreads( ((StandardContext) container).getClearReferencesStopThreads()); + classLoader.setClearReferencesStopTimerThreads( + ((StandardContext) container).getClearReferencesStopTimerThreads()); classLoader.setClearReferencesThreadLocals( ((StandardContext) container).getClearReferencesThreadLocals()); } diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index e20f044c7..dd5ac2606 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -434,6 +434,14 @@ default value of false will be used.

+ +

If true, Tomcat attempts to terminate + java.util.Timerthreads that have been started by the web + application. Unlike standard threads, timer threads can be stopped + safely although there may still be side-effects for the application. If + not specified, the default value of false will be used.

+
+

If true, Tomcat attempts to clear any ThreadLocal objects that are instances of classes loaded by this class loader. -- 2.11.0