FileDocCategorySizeDatePackage
SimplePool.javaAPI DocGlassfish v2 API3259Fri May 04 22:32:58 BST 2007org.apache.jasper.util

SimplePool

public final class SimplePool extends Object
Simple object pool. Based on ThreadPool and few other classes The pool will ignore overflow and return null if empty.
author
Gal Shachor
author
Costin

Fields Summary
private static final int
DEFAULT_SIZE
private Object[]
pool
private int
max
private int
current
private Object
lock
Constructors Summary
public SimplePool()

    
      
	this.max=DEFAULT_SIZE;
	this.pool=new Object[max];
	this.lock=new Object();
    
public SimplePool(int max)

	this.max=max;
	this.pool=new Object[max];
	this.lock=new Object();
    
Methods Summary
public java.lang.Objectget()
Get an object from the pool, null if the pool is empty.

	Object item = null;
	synchronized( lock ) {
	    if( current >= 0 ) {
		item = pool[current];
		current -= 1;
	    }
	}
	return item;
    
public intgetMax()
Return the size of the pool

	return max;
    
public voidput(java.lang.Object o)
Adds the given object to the pool, and does nothing if the pool is full

	synchronized( lock ) {
	    if( current < (max-1) ) {
		current += 1;
		pool[current] = o;
            }
	}