From 642c89e828b2b700f362687f43684dd161466a21 Mon Sep 17 00:00:00 2001 From: remm Date: Sat, 10 Feb 2007 02:19:57 +0000 Subject: [PATCH] - As suggested in 41578, experiment with a thread local pool, but in a simpler way (and with an upper bound). 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 | 47 ++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/java/org/apache/jasper/runtime/JspFactoryImpl.java b/java/org/apache/jasper/runtime/JspFactoryImpl.java index c3a77ad5d..c06d91c6b 100644 --- a/java/org/apache/jasper/runtime/JspFactoryImpl.java +++ b/java/org/apache/jasper/runtime/JspFactoryImpl.java @@ -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 localPool = new ThreadLocal(); 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); } -- 2.11.0