- As suggested in 41578, experiment with a thread local pool, but in a simpler way...
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 10 Feb 2007 02:19:57 +0000 (02:19 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 10 Feb 2007 02:19:57 +0000 (02:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@505617 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/runtime/JspFactoryImpl.java

index c3a77ad..c06d91c 100644 (file)
@@ -46,10 +46,10 @@ public class JspFactoryImpl extends JspFactory {
     private static final String SPEC_VERSION = "2.1";
     private static final boolean USE_POOL = 
         Boolean.valueOf(System.getProperty("org.apache.jasper.runtime.JspFactoryImpl.USE_POOL", "true")).booleanValue();
-    private static final boolean THREAD_LOCAL_POOL = 
-        Boolean.valueOf(System.getProperty("org.apache.jasper.runtime.JspFactoryImpl.THREAD_LOCAL_POOL", "true")).booleanValue();
+    private static final int POOL_SIZE = 
+        Integer.valueOf(System.getProperty("org.apache.jasper.runtime.JspFactoryImpl.POOL_SIZE", "8")).intValue();
 
-    private SimplePool pool = new SimplePool( 100 );
+    private ThreadLocal<PageContextPool> localPool = new ThreadLocal<PageContextPool>();
 
     public PageContext getPageContext(Servlet servlet, ServletRequest request,
             ServletResponse response, String errorPageURL, boolean needsSession,
@@ -92,9 +92,14 @@ public class JspFactoryImpl extends JspFactory {
             int bufferSize, boolean autoflush) {
         try {
             PageContext pc;
-            if( USE_POOL ) {
-                pc = (PageContext) pool.get();
-                if( pc == null ) {
+            if (USE_POOL) {
+                PageContextPool pool = localPool.get();
+                if (pool == null) {
+                    pool = new PageContextPool();
+                    localPool.set(pool);
+                }
+                pc = pool.get();
+                if (pc == null) {
                     pc = new PageContextImpl();
                 }
             } else {
@@ -113,7 +118,7 @@ public class JspFactoryImpl extends JspFactory {
     private void internalReleasePageContext(PageContext pc) {
         pc.release();
         if (USE_POOL && (pc instanceof PageContextImpl)) {
-            pool.put( pc );
+            localPool.get().put(pc);
         }
     }
 
@@ -164,6 +169,34 @@ public class JspFactoryImpl extends JspFactory {
         }
     }
 
+    protected final class PageContextPool  {
+
+        private PageContext[] pool;
+
+        private int current = -1;
+
+        public PageContextPool() {
+            this.pool = new PageContext[POOL_SIZE];
+        }
+
+        public void put(PageContext o) {
+            if (current < (POOL_SIZE - 1)) {
+                current++;
+                pool[current] = o;
+            }
+        }
+
+        public PageContext get() {
+            PageContext item = null;
+            if (current >= 0) {
+                item = pool[current];
+                current--;
+            }
+            return item;
+        }
+
+    }
+
     public JspApplicationContext getJspApplicationContext(ServletContext context) {
         return JspApplicationContextImpl.getInstance(context);
     }