Index: java/org/apache/jasper/runtime/TagHandlerPool.java =================================================================== --- java/org/apache/jasper/runtime/TagHandlerPool.java (revision 1137819) +++ java/org/apache/jasper/runtime/TagHandlerPool.java (working copy) @@ -17,6 +17,10 @@ package org.apache.jasper.runtime; +import java.util.Iterator; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; + import javax.servlet.ServletConfig; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.Tag; @@ -33,15 +37,13 @@ */ public class TagHandlerPool { - private Tag[] handlers; - public static final String OPTION_TAGPOOL = "tagpoolClassName"; public static final String OPTION_MAXSIZE = "tagpoolMaxSize"; private final Log log = LogFactory.getLog(TagHandlerPool.class); - // index of next available tag handler - private int current; + private Queue handlers; + protected InstanceManager instanceManager = null; public static TagHandlerPool getTagHandlerPool(ServletConfig config) { @@ -77,8 +79,7 @@ if (maxSize < 0) { maxSize = Constants.MAX_POOL_SIZE; } - this.handlers = new Tag[maxSize]; - this.current = -1; + this.handlers = new LinkedBlockingQueue(maxSize); instanceManager = InstanceManagerFactory.getInstanceManager(config); } @@ -101,12 +102,9 @@ * if a tag handler cannot be instantiated */ public Tag get(Class handlerClass) throws JspException { - Tag handler; - synchronized (this) { - if (current >= 0) { - handler = handlers[current--]; - return handler; - } + Tag handler = handlers.poll(); + if (handler != null) { + return handler; } // Out of sync block - there is no need for other threads to @@ -134,20 +132,15 @@ * Tag handler to add to this tag handler pool */ public void reuse(Tag handler) { - synchronized (this) { - if (current < (handlers.length - 1)) { - handlers[++current] = handler; - return; + if (!handlers.offer(handler)) { + handler.release(); + try { + instanceManager.destroyInstance(handler); + } catch (Exception e) { + log.warn("Error processing preDestroy on tag instance of " + + handler.getClass().getName(), e); } } - // There is no need for other threads to wait for us to release - handler.release(); - try { - instanceManager.destroyInstance(handler); - } catch (Exception e) { - log.warn("Error processing preDestroy on tag instance of " + - handler.getClass().getName(), e); - } } /** @@ -155,13 +148,15 @@ * handler pool. */ public synchronized void release() { - for (int i = current; i >= 0; i--) { - handlers[i].release(); + Iterator iter = handlers.iterator(); + while (iter.hasNext()) { + Tag handler = iter.next(); + handler.release(); try { - instanceManager.destroyInstance(handlers[i]); + instanceManager.destroyInstance(handler); } catch (Exception e) { log.warn("Error processing preDestroy on tag instance of " + - handlers[i].getClass().getName(), e); + handler.getClass().getName(), e); } } }