Author: remm Date: Fri Feb 9 18:19:57 2007 New Revision: 505617 URL: http://svn.apache.org/viewvc?view=rev&rev=505617 Log: - As suggested in 41578, experiment with a thread local pool, but in a simpler way (and with an upper bound).
Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/JspFactoryImpl.java Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/JspFactoryImpl.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/JspFactoryImpl.java?view=diff&rev=505617&r1=505616&r2=505617 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/JspFactoryImpl.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/runtime/JspFactoryImpl.java Fri Feb 9 18:19:57 2007 @@ -46,10 +46,10 @@ 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 @@ 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 @@ private void internalReleasePageContext(PageContext pc) { pc.release(); if (USE_POOL && (pc instanceof PageContextImpl)) { - pool.put( pc ); + localPool.get().put(pc); } } @@ -162,6 +167,34 @@ factory.internalReleasePageContext(pageContext); return null; } + } + + 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) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]