edu.jhu.tmaj.util
Class ObjectPool

java.lang.Object
  extended by edu.jhu.tmaj.util.ObjectPool

public final class ObjectPool
extends java.lang.Object

A utility that manages a group of resources in a thread safe manner. Any resource that can be initialized and placed into this pool. When threads need to use them, they request a resource and this pool make sure that only one thread at a time will be able to use the resource.


Nested Class Summary
static class ObjectPool.WaitTime
           
 
Constructor Summary
ObjectPool()
          Default constructor.
 
Method Summary
 void addObject(java.lang.Object object)
          Adds an element to the pool.
 int getAvailableCount()
          Gets the number of unused objects in the pool.
 java.lang.Object getObject(ObjectPool.WaitTime waitTime)
          Acquires an object from the pool.
 int getPoolSize()
          Gets the total number of objects in the pool.
 void releaseObject(java.lang.Object object)
          Returns the object to the pool.
 void removeAllObjects()
          Removes all elements from the pool.
 void removeObject(java.lang.Object object)
          Removes an element from the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPool

public ObjectPool()
Default constructor.

Method Detail

addObject

public void addObject(java.lang.Object object)
Adds an element to the pool.


removeObject

public void removeObject(java.lang.Object object)
Removes an element from the pool.


removeAllObjects

public void removeAllObjects()
Removes all elements from the pool.


getObject

public java.lang.Object getObject(ObjectPool.WaitTime waitTime)
Acquires an object from the pool. When the caller has finished with the object, it must call releaseObject to return the object, even in the case of error conditions.

Parameters:
timeout - maximum time in milliseconds to wait for the object. 0 means wait forever *
Returns:
null is returned if the timeout occurred, or the thread was interrupted

releaseObject

public void releaseObject(java.lang.Object object)
Returns the object to the pool.


getPoolSize

public int getPoolSize()
Gets the total number of objects in the pool.


getAvailableCount

public int getAvailableCount()
Gets the number of unused objects in the pool.