- Code cleanup (less thread local manipulation).
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 17 Apr 2007 01:52:50 +0000 (01:52 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 17 Apr 2007 01:52:50 +0000 (01:52 +0000)
- Submitted by Arvind Srinivasan.

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

java/org/apache/catalina/core/ApplicationContext.java

index c6999d2..d4f0b02 100644 (file)
@@ -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> dispatchData =
+        new ThreadLocal<DispatchData>();
 
 
     // --------------------------------------------------------- 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();
+        }
+    }
+
+
 }