FileDocCategorySizeDatePackage
PerThreadTagHandlerPool.javaAPI DocGlassfish v2 API5346Fri May 04 22:32:54 BST 2007org.apache.jasper.runtime

PerThreadTagHandlerPool

public class PerThreadTagHandlerPool extends TagHandlerPool
Thread-local based pool of tag handlers that can be reused.
author
Jan Luehe
author
Costin Manolache

Fields Summary
private int
maxSize
private Vector
perThreadDataVector
private ThreadLocal
perThread
Constructors Summary
public PerThreadTagHandlerPool()
Constructs a tag handler pool with the default capacity.

        super();
        perThreadDataVector = new Vector();
    
Methods Summary
public javax.servlet.jsp.tagext.Tagget(java.lang.Class handlerClass)
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

        PerThreadData ptd = (PerThreadData)perThread.get();
        if(ptd.current >=0 ) {
            return ptd.handlers[ptd.current--];
        } else {
	    try {
		return (Tag) handlerClass.newInstance();
	    } catch (Exception e) {
		throw new JspException(e.getMessage(), e);
	    }
	}
    
protected voidinit(javax.servlet.ServletConfig config)

        maxSize = Constants.MAX_POOL_SIZE;
        String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
        if (maxSizeS != null) {
            maxSize = Integer.parseInt(maxSizeS);
            if (maxSize < 0) {
                maxSize = Constants.MAX_POOL_SIZE;
            }
        }

        perThread = new ThreadLocal() {
            protected Object initialValue() {
                PerThreadData ptd = new PerThreadData();
                ptd.handlers = new Tag[maxSize];
                ptd.current = -1;
                perThreadDataVector.addElement(ptd);
                return ptd;
            }
        };
    
public voidrelease()
Calls the release() method of all tag handlers in this tag handler pool.

        
        Enumeration enumeration = perThreadDataVector.elements();
        while (enumeration.hasMoreElements()) {
	    PerThreadData ptd = (PerThreadData)enumeration.nextElement();
            if (ptd.handlers != null) {
                for (int i=ptd.current; i>=0; i--) {
                    if (ptd.handlers[i] != null) {
                        ptd.handlers[i].release();
		    }
                }
            }
        }
    
public voidreuse(javax.servlet.jsp.tagext.Tag handler)
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

        PerThreadData ptd=(PerThreadData)perThread.get();
	if (ptd.current < (ptd.handlers.length - 1)) {
	    ptd.handlers[++ptd.current] = handler;
        } else {
            handler.release();
        }