com.ibm.xdms.utils
Class ObjectPool

java.lang.Object
  extended by com.ibm.xdms.utils.ObjectPool
Direct Known Subclasses:
XMLUtilsPool

public class ObjectPool
extends java.lang.Object

A general purpose object pool.


Field Summary
static java.lang.String COPYRIGHT
           
protected  java.lang.Object lock
          An object used for synchronization *
protected  int maxSize
          Maximum size of the pool *
protected  int minSize
          Minimum size of the pool *
protected  ObjectFactory objectFactory
          The ObjectFactory used to create and destroy objects *
protected  java.util.Stack<java.lang.Object> pool
          A stack for pooling the objects *
 
Constructor Summary
protected ObjectPool()
          Empty constructor used for subclassing.
  ObjectPool(ObjectFactory objectFactory)
          Constructs a default ObjectPool.
  ObjectPool(ObjectFactory objectFactory, int minSize, int maxSize)
          Constructs an ObjectPool with the specified number of minimum and maximum objects.
 
Method Summary
 void checkin(java.lang.Object o)
          Checkin an object back into the pool.
 java.lang.Object checkout()
          Checkout an object from the pool.
protected  void init(ObjectFactory objectFactory, int minSize, int maxSize)
          Initializes an ObjectPool with the specified number of minimum and maximum objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT

lock

protected java.lang.Object lock
An object used for synchronization *


minSize

protected int minSize
Minimum size of the pool *


maxSize

protected int maxSize
Maximum size of the pool *


pool

protected java.util.Stack<java.lang.Object> pool
A stack for pooling the objects *


objectFactory

protected ObjectFactory objectFactory
The ObjectFactory used to create and destroy objects *

Constructor Detail

ObjectPool

protected ObjectPool()
Empty constructor used for subclassing. The init() method must be invoked by the subclass.


ObjectPool

public ObjectPool(ObjectFactory objectFactory)
Constructs a default ObjectPool. Default min of 10 and a max of 100. objects.

Parameters:
objectFactory - The ObjectFactory used to create or destroy objects.

ObjectPool

public ObjectPool(ObjectFactory objectFactory,
                  int minSize,
                  int maxSize)
Constructs an ObjectPool with the specified number of minimum and maximum objects.

Parameters:
objectFactory - The ObjectFactory used to create or destroy objects.
minSize - The minimum number of objects that are kept in the pool.
maxSize - The maximum number of objects that are kept in the pool.
Method Detail

init

protected void init(ObjectFactory objectFactory,
                    int minSize,
                    int maxSize)
Initializes an ObjectPool with the specified number of minimum and maximum objects.

Parameters:
objectFactory - The ObjectFactory used to create or destroy objects.
minSize - The minimum number of objects that are kept in the pool.
maxSize - The maximum number of objects that are kept in the pool.

checkout

public java.lang.Object checkout()
Checkout an object from the pool. Remember to check the object back into the pool when done.

Returns:
Returns an object.

checkin

public void checkin(java.lang.Object o)
Checkin an object back into the pool.

Parameters:
o - An object to check back into the pool.