You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/01/23 13:17:42 UTC
svn commit: r1560659 - in /tomcat/trunk/java/org/apache/catalina:
connector/CoyoteAdapter.java core/ApplicationDispatcher.java
core/ContainerBase.java core/StandardWrapper.java
Author: markt
Date: Thu Jan 23 12:17:41 2014
New Revision: 1560659
URL: http://svn.apache.org/r1560659
Log:
More migrations to Context bind()/unbind()
Modified:
tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1560659&r1=1560658&r2=1560659&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu Jan 23 12:17:41 2014
@@ -316,15 +316,12 @@ public class CoyoteAdapter implements Ad
req.getAttributes().remove(RequestDispatcher.ERROR_EXCEPTION);
ReadListener readListener = req.getReadListener();
if (readListener != null) {
- ClassLoader oldCL =
- Thread.currentThread().getContextClassLoader();
- ClassLoader newCL =
- request.getContext().getLoader().getClassLoader();
+ ClassLoader oldCL = null;
try {
- Thread.currentThread().setContextClassLoader(newCL);
+ oldCL = request.getContext().bind(false, null);
readListener.onError(t);
} finally {
- Thread.currentThread().setContextClassLoader(oldCL);
+ request.getContext().unbind(false, oldCL);
}
}
if (t != null) {
@@ -339,15 +336,12 @@ public class CoyoteAdapter implements Ad
RequestDispatcher.ERROR_EXCEPTION);
req.getAttributes().remove(RequestDispatcher.ERROR_EXCEPTION);
if (res.getWriteListener() != null) {
- ClassLoader oldCL =
- Thread.currentThread().getContextClassLoader();
- ClassLoader newCL =
- request.getContext().getLoader().getClassLoader();
+ ClassLoader oldCL = null;
try {
- Thread.currentThread().setContextClassLoader(newCL);
+ oldCL = request.getContext().bind(false, null);
res.getWriteListener().onError(t);
} finally {
- Thread.currentThread().setContextClassLoader(oldCL);
+ request.getContext().unbind(false, oldCL);
}
}
if (t != null) {
@@ -360,12 +354,9 @@ public class CoyoteAdapter implements Ad
WriteListener writeListener = res.getWriteListener();
ReadListener readListener = req.getReadListener();
if (writeListener != null && status == SocketStatus.OPEN_WRITE) {
- ClassLoader oldCL =
- Thread.currentThread().getContextClassLoader();
- ClassLoader newCL =
- request.getContext().getLoader().getClassLoader();
+ ClassLoader oldCL = null;
try {
- Thread.currentThread().setContextClassLoader(newCL);
+ oldCL = request.getContext().bind(false, null);
res.onWritePossible();
if (request.isFinished() && req.sendAllDataReadEvent() &&
readListener != null) {
@@ -376,16 +367,13 @@ public class CoyoteAdapter implements Ad
writeListener.onError(t);
throw t;
} finally {
- Thread.currentThread().setContextClassLoader(oldCL);
+ request.getContext().unbind(false, oldCL);
}
success = true;
} else if (readListener != null && status == SocketStatus.OPEN_READ) {
- ClassLoader oldCL =
- Thread.currentThread().getContextClassLoader();
- ClassLoader newCL =
- request.getContext().getLoader().getClassLoader();
+ ClassLoader oldCL = null;
try {
- Thread.currentThread().setContextClassLoader(newCL);
+ oldCL = request.getContext().bind(false, null);
readListener.onDataAvailable();
if (request.isFinished() && req.sendAllDataReadEvent()) {
readListener.onAllDataRead();
@@ -395,7 +383,7 @@ public class CoyoteAdapter implements Ad
readListener.onError(t);
throw t;
} finally {
- Thread.currentThread().setContextClassLoader(oldCL);
+ request.getContext().unbind(false, oldCL);
}
success = true;
}
@@ -548,17 +536,14 @@ public class CoyoteAdapter implements Ad
if (readListener != null && request.isFinished()) {
// Possible the all data may have been read during service()
// method so this needs to be checked here
- ClassLoader oldCL =
- Thread.currentThread().getContextClassLoader();
- ClassLoader newCL =
- request.getContext().getLoader().getClassLoader();
+ ClassLoader oldCL = null;
try {
- Thread.currentThread().setContextClassLoader(newCL);
+ oldCL = request.getContext().bind(false, null);
if (req.sendAllDataReadEvent()) {
req.getReadListener().onAllDataRead();
}
} finally {
- Thread.currentThread().setContextClassLoader(oldCL);
+ request.getContext().unbind(false, oldCL);
}
}
} else if (!comet) {
Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java?rev=1560659&r1=1560658&r2=1560659&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java Thu Jan 23 12:17:41 2014
@@ -665,15 +665,7 @@ final class ApplicationDispatcher implem
// Checking to see if the context classloader is the current context
// classloader. If it's not, we're saving it, and setting the context
// classloader to the Context classloader
- ClassLoader oldCCL = Thread.currentThread().getContextClassLoader();
- ClassLoader contextClassLoader = context.getLoader().getClassLoader();
-
- if (oldCCL != contextClassLoader) {
- Thread.currentThread().setContextClassLoader(contextClassLoader);
- context.getThreadBindingListener().bind();
- } else {
- oldCCL = null;
- }
+ ClassLoader oldCCL = context.bind(false, null);
// Initialize local variables we may need
HttpServletResponse hresponse = state.hresponse;
@@ -796,10 +788,7 @@ final class ApplicationDispatcher implem
}
// Reset the old context class loader
- if (oldCCL != null) {
- context.getThreadBindingListener().unbind();
- Thread.currentThread().setContextClassLoader(oldCCL);
- }
+ context.unbind(false, oldCCL);
// Unwrap request/response if needed
// See Bugzilla 30949
Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1560659&r1=1560658&r2=1560659&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Thu Jan 23 12:17:41 2014
@@ -55,7 +55,6 @@ import org.apache.catalina.LifecycleStat
import org.apache.catalina.Loader;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Realm;
-import org.apache.catalina.ThreadBindingListener;
import org.apache.catalina.Valve;
import org.apache.catalina.Wrapper;
import org.apache.catalina.connector.Request;
@@ -1349,16 +1348,10 @@ public abstract class ContainerBase exte
if (loader == null) {
return;
}
+
// Ensure background processing for Contexts and Wrappers
// is performed under the web app's class loader
- originalClassLoader =
- Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(
- loader.getClassLoader());
- ThreadBindingListener tbl = ((Context) container).getThreadBindingListener();
- if (tbl != null) {
- tbl.bind();
- }
+ originalClassLoader = ((Context) container).bind(false, null);
}
container.backgroundProcess();
Container[] children = container.findChildren();
@@ -1371,15 +1364,8 @@ public abstract class ContainerBase exte
ExceptionUtils.handleThrowable(t);
log.error("Exception invoking periodic operation: ", t);
} finally {
- if (originalClassLoader != null) {
- if (container instanceof Context) {
- ThreadBindingListener tbl = ((Context) container).getThreadBindingListener();
- if (tbl != null) {
- tbl.unbind();
- }
- }
- Thread.currentThread().setContextClassLoader(
- originalClassLoader);
+ if (container instanceof Context) {
+ ((Context) container).unbind(false, originalClassLoader);
}
}
}
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=1560659&r1=1560658&r2=1560659&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java Thu Jan 23 12:17:41 2014
@@ -554,17 +554,15 @@ public class StandardWrapper extends Con
// The logic to determine this safely is more complex than one might
// expect. allocate() already has the necessary logic so re-use it.
// Make sure the Servlet is loaded with the right class loader
- ClassLoader old = Thread.currentThread().getContextClassLoader();
- ClassLoader webappClassLoader =
- ((Context) getParent()).getLoader().getClassLoader();
+ ClassLoader oldCL = null;
try {
- Thread.currentThread().setContextClassLoader(webappClassLoader);
+ oldCL = ((Context) getParent()).bind(false, null);
Servlet s = allocate();
deallocate(s);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
} finally {
- Thread.currentThread().setContextClassLoader(old);
+ ((Context) getParent()).unbind(false, oldCL);
}
return singleThreadModel;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org