Speed up shut down when ThreadLocalLeakPreventionListener is enabled
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 2 Mar 2011 15:19:58 +0000 (15:19 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 2 Mar 2011 15:19:58 +0000 (15:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1076249 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java
webapps/docs/changelog.xml

index fa82cdb..42a3eff 100644 (file)
@@ -53,10 +53,13 @@ import org.apache.tomcat.util.threads.ThreadPoolExecutor;
  * 
  */
 public class ThreadLocalLeakPreventionListener implements LifecycleListener,
-    ContainerListener {
+        ContainerListener {
+
     private static final Log log =
         LogFactory.getLog(ThreadLocalLeakPreventionListener.class);
 
+    private volatile boolean serverStopping = false;
+
     /**
      * The string manager for this package.
      */
@@ -72,7 +75,7 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener,
         try {
             Lifecycle lifecycle = event.getLifecycle();
             if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) &&
-                lifecycle instanceof Server) {
+                    lifecycle instanceof Server) {
                 // when the server starts, we register ourself as listener for
                 // all context
                 // as well as container event listener so that we know when new
@@ -81,8 +84,15 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener,
                 registerListenersForServer(server);
             }
 
+            if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()) &&
+                    lifecycle instanceof Server) {
+                // Server is shutting down, so thread pools will be shut down so
+                // there is no need to clean the threads
+                serverStopping = true;
+            }
+
             if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) &&
-                lifecycle instanceof Context) {
+                    lifecycle instanceof Context) {
                 stopIdleThreads((Context) lifecycle);
             }
         } catch (Exception e) {
@@ -182,6 +192,8 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener,
      *            of its parent Service.
      */
     private void stopIdleThreads(Context context) {
+        if (serverStopping) return;
+
         if (context instanceof StandardContext &&
             !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
             log.debug("Not renewing threads when the context is stopping, "
index 7e52d4b..7555b01 100644 (file)
         Improve handling of SSL renegotiation by failing earlier when the
         request body contains more bytes than maxSavePostSize. (markt)
       </fix>
+      <fix>
+        Improve shut down speed by not renewing threads during shut down when
+        the <code>ThreadLocalLeakPreventionListener</code> is enabled. (markt)  
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">