bug 50459: StandardContext.bindThread() and unbindThread() are not symmetrical and...
authorslaurent <slaurent@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 12 Dec 2010 00:10:39 +0000 (00:10 +0000)
committerslaurent <slaurent@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 12 Dec 2010 00:10:39 +0000 (00:10 +0000)
https://issues.apache.org/bugzilla/show_bug.cgi?id=50459

This fixes the bug that was introduced by http://svn.apache.org/viewvc?rev=1044145&view=rev (introduced a dedicated thread when starting and stopping web applications to avoid mem leak)

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1044746 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardContext.java

index 5f9a9bc..ac48d8d 100644 (file)
@@ -4862,10 +4862,10 @@ public class StandardContext extends ContainerBase
                 if ((loader != null) && (loader instanceof Lifecycle))
                     ((Lifecycle) loader).start();
 
-                // Unbinding thread
+                // since the loader just started, the webapp classloader is now
+                // created by calling unbindThread and bindThread in a row, we
+                // setup the current Thread CCL to be the webapp classloader
                 unbindThread(oldCCL);
-
-                // Binding thread
                 oldCCL = bindThread();
 
                 // Initialize logger again. Other components might have used it too early, 
@@ -5542,7 +5542,7 @@ public class StandardContext extends ContainerBase
                 (getLoader().getClassLoader());
         }
 
-        DirContextURLStreamHandler.bind(getResources());
+        DirContextURLStreamHandler.bindThread(getResources());
 
         if (isUseNaming()) {
             try {
@@ -5563,16 +5563,13 @@ public class StandardContext extends ContainerBase
      */
     private void unbindThread(ClassLoader oldContextClassLoader) {
 
-        Thread.currentThread().setContextClassLoader(oldContextClassLoader);
-
-        oldContextClassLoader = null;
-
         if (isUseNaming()) {
             ContextBindings.unbindThread(this, this);
         }
 
-        DirContextURLStreamHandler.unbind();
+        DirContextURLStreamHandler.unbindThread();
 
+        Thread.currentThread().setContextClassLoader(oldContextClassLoader);
     }