Author: markt
Date: Wed Mar  2 15:19:58 2011
New Revision: 1076249

URL: http://svn.apache.org/viewvc?rev=1076249&view=rev
Log:
Speed up shut down when ThreadLocalLeakPreventionListener is enabled

Modified:
    
tomcat/trunk/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/trunk/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java?rev=1076249&r1=1076248&r2=1076249&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java
 (original)
+++ 
tomcat/trunk/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java
 Wed Mar  2 15:19:58 2011
@@ -53,10 +53,13 @@ import org.apache.tomcat.util.threads.Th
  * 
  */
 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 ThreadLocalLeakPreventionLi
         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 ThreadLocalLeakPreventionLi
                 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 ThreadLocalLeakPreventionLi
      *            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, "

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1076249&r1=1076248&r2=1076249&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Mar  2 15:19:58 2011
@@ -57,6 +57,10 @@
         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">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to