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,
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 {
private void internalReleasePageContext(PageContext pc) {
pc.release();
if (USE_POOL && (pc instanceof PageContextImpl)) {
- pool.put( pc );
+ localPool.get().put(pc);
}
}
}
}
+ 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);
}