Save This Page
Home » commons-pool-1.4-src » org.apache.commons » pool » impl » [javadoc | source]
org.apache.commons.pool.impl
public class: StackObjectPool [javadoc | source]
java.lang.Object
   org.apache.commons.pool.BaseObjectPool
      org.apache.commons.pool.impl.StackObjectPool

All Implemented Interfaces:
    ObjectPool

A simple, Stack -based ObjectPool implementation.

Given a PoolableObjectFactory , this class will maintain a simple pool of instances. A finite number of "sleeping" or idle instances is enforced, but when the pool is empty, new instances are created to support the new load. Hence this class places no limit on the number of "active" instances created by the pool, but is quite useful for re-using Objects without introducing artificial limits.

Field Summary
protected static final  int DEFAULT_MAX_SLEEPING    The default cap on the number of "sleeping" instances in the pool. 
protected static final  int DEFAULT_INIT_SLEEPING_CAPACITY    The default initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.) 
protected  Stack _pool    My pool. 
protected  PoolableObjectFactory _factory    My PoolableObjectFactory
protected  int _maxSleeping    The cap on the number of "sleeping" instances in the pool. 
protected  int _numActive    Number of object borrowed but not yet returned to the pool. 
Constructor:
 public StackObjectPool() 
 public StackObjectPool(int maxIdle) 
 public StackObjectPool(PoolableObjectFactory factory) 
    Create a new StackObjectPool using the specified factory to create new instances.
 public StackObjectPool(int maxIdle,
    int initIdleCapacity) 
    Parameters:
    maxIdle - cap on the number of "sleeping" instances in the pool
    initIdleCapacity - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
    Also see:
    StackObjectPool(PoolableObjectFactory, int, int)
 public StackObjectPool(PoolableObjectFactory factory,
    int maxIdle) 
    Create a new SimpleObjectPool using the specified factory to create new instances, capping the number of "sleeping" instances to max.
    Parameters:
    factory - the PoolableObjectFactory used to populate the pool
    maxIdle - cap on the number of "sleeping" instances in the pool
 public StackObjectPool(PoolableObjectFactory factory,
    int maxIdle,
    int initIdleCapacity) 
    Create a new SimpleObjectPool using the specified factory to create new instances, capping the number of "sleeping" instances to max, and initially allocating a container capable of containing at least init instances.
    Parameters:
    factory - the PoolableObjectFactory used to populate the pool
    maxIdle - cap on the number of "sleeping" instances in the pool
    initIdleCapacity - initial size of the pool (this specifies the size of the container, it does not cause the pool to be pre-populated.)
Method from org.apache.commons.pool.impl.StackObjectPool Summary:
addObject,   borrowObject,   clear,   close,   getNumActive,   getNumIdle,   invalidateObject,   returnObject,   setFactory
Methods from org.apache.commons.pool.BaseObjectPool:
addObject,   assertOpen,   borrowObject,   clear,   close,   getNumActive,   getNumIdle,   invalidateObject,   isClosed,   returnObject,   setFactory
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.pool.impl.StackObjectPool Detail:
 public synchronized  void addObject() throws Exception 
    Create an object, and place it into the pool. addObject() is useful for "pre-loading" a pool with idle objects.
 public synchronized Object borrowObject() throws Exception 
 public synchronized  void clear() 
    Clears any objects sitting idle in the pool.
 public  void close() throws Exception 
 public synchronized int getNumActive() 
    Return the number of instances currently borrowed from this pool.
 public synchronized int getNumIdle() 
    Return the number of instances currently idle in this pool.
 public synchronized  void invalidateObject(Object obj) throws Exception 
 public synchronized  void returnObject(Object obj) throws Exception 
 public synchronized  void setFactory(PoolableObjectFactory factory) throws IllegalStateException 
    Sets the factory this pool uses to create new instances. Trying to change the factory while there are borrowed objects will throw an IllegalStateException .