From 5921d6f1e311bba74a26d14b1f6d1c6c959d546b Mon Sep 17 00:00:00 2001 From: slaurent Date: Sun, 12 Dec 2010 00:10:39 +0000 Subject: [PATCH] bug 50459: StandardContext.bindThread() and unbindThread() are not symmetrical and not limited to current thread 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 | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 5f9a9bc75..ac48d8d64 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -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); } -- 2.11.0