From e7b0ce77ccc646e9dd8b2b8bbae9010d95fb450d Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 2 Mar 2011 15:19:58 +0000 Subject: [PATCH] Speed up shut down when ThreadLocalLeakPreventionListener is enabled git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1076249 13f79535-47bb-0310-9956-ffa450edef68 --- .../core/ThreadLocalLeakPreventionListener.java | 18 +++++++++++++++--- webapps/docs/changelog.xml | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java b/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java index fa82cdb52..42a3eff7e 100644 --- a/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java +++ b/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java @@ -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, " diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 7e52d4b2f..7555b0147 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -57,6 +57,10 @@ Improve handling of SSL renegotiation by failing earlier when the request body contains more bytes than maxSavePostSize. (markt) + + Improve shut down speed by not renewing threads during shut down when + the ThreadLocalLeakPreventionListener is enabled. (markt) + -- 2.11.0