From 8e8386aa867bd846fc3e18e8f63391c602e71ca9 Mon Sep 17 00:00:00 2001 From: slaurent Date: Thu, 9 Dec 2010 18:55:04 +0000 Subject: [PATCH] bug 49159: Improve ThreadLocal memory leak clean-up https://issues.apache.org/bugzilla/show_bug.cgi?id=49159 some formatting after discussion over the list (operator at the end of line, unnecessary cast) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1044083 13f79535-47bb-0310-9956-ffa450edef68 --- .../core/ThreadLocalLeakPreventionListener.java | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java b/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java index f26ad339b..fa82cdb52 100644 --- a/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java +++ b/java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java @@ -71,8 +71,8 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener, public void lifecycleEvent(LifecycleEvent event) { try { Lifecycle lifecycle = event.getLifecycle(); - if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) - && lifecycle instanceof Server) { + if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) && + 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 +81,8 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener, registerListenersForServer(server); } - if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) - && lifecycle instanceof Context) { + if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) && + lifecycle instanceof Context) { stopIdleThreads((Context) lifecycle); } } catch (Exception e) { @@ -145,8 +145,8 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener, protected void processContainerAddChild(Container parent, Container child) { if (log.isDebugEnabled()) - log.debug("Process addChild[parent=" + parent + ",child=" + child - + "]"); + log.debug("Process addChild[parent=" + parent + ",child=" + child + + "]"); if (child instanceof Context) { registerContextListener((Context) child); @@ -158,22 +158,18 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener, } - protected void processContainerRemoveChild(Container parent, + protected void processContainerRemoveChild(Container parent, Container child) { if (log.isDebugEnabled()) - log.debug("Process removeChild[parent=" + parent + ",child=" - + child + "]"); + log.debug("Process removeChild[parent=" + parent + ",child=" + + child + "]"); if (child instanceof Context) { Context context = (Context) child; context.removeLifecycleListener(this); - } else if (child instanceof Host) { - Host host = (Host) child; - host.removeContainerListener(this); - } else if (child instanceof Engine) { - Engine engine = (Engine) child; - engine.removeContainerListener(this); + } else if (child instanceof Host || child instanceof Engine) { + child.removeContainerListener(this); } } @@ -186,9 +182,10 @@ public class ThreadLocalLeakPreventionListener implements LifecycleListener, * of its parent Service. */ private void stopIdleThreads(Context context) { - if (context instanceof StandardContext && + if (context instanceof StandardContext && !((StandardContext) context).getRenewThreadsWhenStoppingContext()) { - log.debug("Not renewing threads when the context is stopping, it is configured not to do it."); + log.debug("Not renewing threads when the context is stopping, " + + "it is configured not to do it."); return; } -- 2.11.0