bug 49159: Improve ThreadLocal memory leak clean-up
authorslaurent <slaurent@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Dec 2010 18:55:04 +0000 (18:55 +0000)
committerslaurent <slaurent@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Dec 2010 18:55:04 +0000 (18:55 +0000)
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

java/org/apache/catalina/core/ThreadLocalLeakPreventionListener.java

index f26ad33..fa82cdb 100644 (file)
@@ -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;
         }