From: remm Date: Tue, 17 Apr 2007 01:52:50 +0000 (+0000) Subject: - Code cleanup (less thread local manipulation). X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e0f6e6cb33bf6ab8164147c8a1e88453e9e334d1;p=tomcat7.0 - Code cleanup (less thread local manipulation). - Submitted by Arvind Srinivasan. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@529466 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index c6999d289..d4f0b025d 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -137,15 +137,10 @@ public class ApplicationContext /** - * Thread local mapping data. + * Thread local data used during request dispatch. */ - private ThreadLocal localMappingData = new ThreadLocal(); - - - /** - * Thread local URI message bytes. - */ - private ThreadLocal localUriMB = new ThreadLocal(); + private ThreadLocal dispatchData = + new ThreadLocal(); // --------------------------------------------------------- Public Methods @@ -377,17 +372,16 @@ public class ApplicationContext if (path == null) return (null); - // Retrieve the thread local URI - MessageBytes uriMB = (MessageBytes) localUriMB.get(); - if (uriMB == null) { - uriMB = MessageBytes.newInstance(); - CharChunk uriCC = uriMB.getCharChunk(); - uriCC.setLimit(-1); - localUriMB.set(uriMB); - } else { - uriMB.recycle(); + // Use the thread local URI and mapping data + DispatchData dd = dispatchData.get(); + if (dd == null) { + dd = new DispatchData(); + dispatchData.set(dd); } + MessageBytes uriMB = dd.uriMB; + uriMB.recycle(); + // Get query string String queryString = null; int pos = path.indexOf('?'); @@ -397,12 +391,8 @@ public class ApplicationContext pos = path.length(); } - // Retrieve the thread local mapping data - MappingData mappingData = (MappingData) localMappingData.get(); - if (mappingData == null) { - mappingData = new MappingData(); - localMappingData.set(mappingData); - } + // Use the thread local mapping data + MappingData mappingData = dd.mappingData; // Map the URI CharChunk uriCC = uriMB.getCharChunk(); @@ -963,4 +953,22 @@ public class ApplicationContext } + /** + * Internal class used as thread-local storage when doing path + * mapping during dispatch. + */ + private final class DispatchData { + + public MessageBytes uriMB; + public MappingData mappingData; + + public DispatchData() { + uriMB = MessageBytes.newInstance(); + CharChunk uriCC = uriMB.getCharChunk(); + uriCC.setLimit(-1); + mappingData = new MappingData(); + } + } + + }