Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 94935 invoked from network); 18 Jan 2003 20:14:22 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 18 Jan 2003 20:14:22 -0000 Received: (qmail 25518 invoked by uid 97); 18 Jan 2003 20:15:43 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@jakarta.apache.org Received: (qmail 25474 invoked by uid 97); 18 Jan 2003 20:15:41 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 25462 invoked by uid 98); 18 Jan 2003 20:15:40 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) X-Injected-Via-Gmane: http://gmane.org/ To: tomcat-dev@jakarta.apache.org Path: not-for-mail From: Costin Manolache Subject: Re: DO NOT REPLY [Bug 16001] - Tag.release() not invoked Date: Sat, 18 Jan 2003 12:10:50 -0800 Lines: 138 Message-ID: References: <66337F04F2A1E440BF87F2080B5F5370014819E9@madison.dc.Blackboard.com> <3E286195.7040908@gefionsoftware.com> <3E28C451.2010001@mail.more.net> <002501c2bea5$dc8b6780$d2b32b04@dslverizon.net> <3E291214.7080404@apache.org> <012d01c2bed1$b5045ec0$d2b32b04@dslverizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: usenet@main.gmane.org User-Agent: KNode/0.7.1 Sender: news X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Bill Barker wrote: > If tag-pooling works for you, I'm happy for you. The current > implementation > doesn't work for me big time. However, I'm very interested in Costin's > claim that it can be done thread-local. One quick question ( looking at generated code ) - why is the TP limited to 5 instances ? If you expect 20+ concurent requests ( where the TP would actually matter ) - you'll have the overhead of TP sync, and almost no benefit. Can you try again with a larger capacity ? Regarding the "claim" that it can be done thread-local: I attached a first draft, I'll enhance it later ( it could use ThreadWithAttributes - to save one extra hashtable lookup ). Let me know if it helps. Costin package org.apache.jasper.runtime; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.Tag; import org.apache.jasper.Constants; import java.util.Hashtable; import java.util.Enumeration; /** * Pool of tag handlers that can be reused. * Experimental: use thread local. * * @author Jan Luehe */ public class TagHandlerPool { private int maxSize=100; private int initialSize=5; private ThreadLocal perThread=new ThreadLocal(); // for cleanup private Hashtable threadData=new Hashtable(); private static class PerThreadData { Tag handlers[]; int current; } /** * Constructs a tag handler pool with the default capacity. */ public TagHandlerPool() { this(Constants.MAX_POOL_SIZE); } /** * Constructs a tag handler pool with the given capacity. * * @param capacity Tag handler pool capacity */ public TagHandlerPool(int capacity) { this.maxSize = capacity; //this.handlers = new Tag[capacity]; //this.current = -1; } /** * Gets the next available tag handler from this tag handler pool, * instantiating one if this tag handler pool is empty. * * @param handlerClass Tag handler class * * @return Reused or newly instantiated tag handler * * @throws JspException if a tag handler cannot be instantiated */ public Tag get(Class handlerClass) throws JspException { PerThreadData ptd=(PerThreadData)perThread.get(); if( ptd!=null && ptd.current >=0 ) { return ptd.handlers[ptd.current--]; } else { try { return (Tag) handlerClass.newInstance(); } catch (Exception e) { throw new JspException(e.getMessage(), e); } } } /** * Adds the given tag handler to this tag handler pool, unless this tag * handler pool has already reached its capacity, in which case the tag * handler's release() method is called. * * @param handler Tag handler to add to this tag handler pool */ public void reuse(Tag handler) { PerThreadData ptd=(PerThreadData)perThread.get(); if( ptd==null ) { ptd=new PerThreadData(); ptd.handlers=new Tag[ initialSize ]; ptd.current=0; threadData.put( ptd, ptd ); } if (ptd.current < (ptd.handlers.length - 1)) { ptd.handlers[++ptd.current] = handler; return; } // no more space if( ptd.handlers.length < maxSize ) { // reallocate Tag newH[]=new Tag[ptd.handlers.length + initialSize]; System.arraycopy(ptd.handlers, 0, newH, 0, ptd.handlers.length); ptd.handlers=newH; ptd.handlers[++ptd.current]=handler; return; } //else handler.release(); } /** * Calls the release() method of all available tag handlers in this tag * handler pool. */ public synchronized void release() { Enumeration ptdE=threadData.keys(); while( ptdE.hasMoreElements() ) { PerThreadData ptd=(PerThreadData)ptdE.nextElement(); for (int i=ptd.current; i>=0; i--) { ptd.handlers[i].release(); } } } } -- To unsubscribe, e-mail: For additional commands, e-mail: