Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48971
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 1 Jun 2010 16:59:14 +0000 (16:59 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 1 Jun 2010 16:59:14 +0000 (16:59 +0000)
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
java/org/apache/catalina/loader/WebappClassLoader.java
java/org/apache/catalina/loader/WebappLoader.java
webapps/docs/config/context.xml

index 9b393d8..0e0ec5e 100644 (file)
@@ -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
-     * <code>false</code> will be used. 
+     * <code>false</code> 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 <code>false</code> 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() {
index 561b2e6..74388df 100644 (file)
@@ -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
-     * <code>false</code> will be used. Note that instances of
-     * java.util.TimerThread will always be terminate since a safe method exists
-     * to do so.
+     * <code>false</code> 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 <code>false</code> 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;
                     }
index 3d40a13..8ca4654 100644 (file)
@@ -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());
             }
index e20f044..dd5ac26 100644 (file)
         default value of <code>false</code> will be used.</p>
       </attribute>
 
+      <attribute name="clearReferencesStopTimerThreads" required = "false">
+        <p>If <code>true</code>, Tomcat attempts to terminate
+        <code>java.util.Timer</code>threads 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 <code>false</code> will be used.</p>
+      </attribute>
+
       <attribute name="clearReferencesThreadLocals" required="false">
         <p>If <code>true</code>, Tomcat attempts to clear any ThreadLocal
         objects that are instances of classes loaded by this class loader.