From: markt 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.