| org.apache.commons.pool.ObjectPool
All known Subclasses: org.apache.commons.pool.BaseObjectPool, org.apache.commons.pool.impl.GenericObjectPool, org.apache.commons.pool.impl.StackObjectPool, org.apache.commons.pool.impl.SoftReferenceObjectPool,
ObjectPool | public interface ObjectPool (Code) | | A pooling interface.
ObjectPool defines a trivially simple pooling interface. The only
required methods are
ObjectPool.borrowObject borrowObject and
ObjectPool.returnObject returnObject .
Example of use:
Object obj = null;
try {
obj = pool.borrowObject();
//...use the object...
} catch(Exception e) {
//...handle any exceptions...
} finally {
// make sure the object is returned to the pool
if(null != obj) {
pool.returnObject(obj);
}
} |
See
org.apache.commons.pool.BaseObjectPool BaseObjectPool for a simple base implementation.
author: Rodney Waldhoff version: $Revision: 155430 $ $Date: 2005-02-26 08:13:28 -0500 (Sat, 26 Feb 2005) $ |
Method Summary | |
void | addObject() Create an object using my
ObjectPool.setFactory factory or other
implementation dependent mechanism, and place it into the pool. | Object | borrowObject() Obtain an instance from my pool. | void | clear() Clears any objects sitting idle in the pool, releasing any
associated resources (optional operation). | void | close() Close this pool, and free any resources associated with it. | int | getNumActive() Return the number of instances
currently borrowed from my pool
(optional operation). | int | getNumIdle() Return the number of instances
currently idle in my pool (optional operation). | void | invalidateObject(Object obj) Invalidates an object from the pool
By contract, obj MUST have been obtained
using
ObjectPool.borrowObject() borrowObject or a related method as defined in an implementation
or sub-interface. | void | returnObject(Object obj) Return an instance to my pool. | void | setFactory(PoolableObjectFactory factory) Sets the
PoolableObjectFactory factory I use
to create new instances (optional operation). |
addObject | void addObject() throws Exception(Code) | | Create an object using my
ObjectPool.setFactory factory or other
implementation dependent mechanism, and place it into the pool.
addObject() is useful for "pre-loading" a pool with idle objects.
(Optional operation).
|
borrowObject | Object borrowObject() throws Exception(Code) | | Obtain an instance from my pool.
By contract, clients MUST return
the borrowed instance using
ObjectPool.returnObject(java.lang.Object) returnObject or a related method as defined in an implementation
or sub-interface.
The behaviour of this method when the pool has been exhausted
is not specified (although it may be specified by implementations).
an instance from my pool. |
close | void close() throws Exception(Code) | | Close this pool, and free any resources associated with it.
|
getNumIdle | int getNumIdle() throws UnsupportedOperationException(Code) | | Return the number of instances
currently idle in my pool (optional operation).
This may be considered an approximation of the number
of objects that can be
ObjectPool.borrowObject borrowed without creating any new instances.
the number of instances currently idle in my pool throws: UnsupportedOperationException - if this implementation does not support the operation |
invalidateObject | void invalidateObject(Object obj) throws Exception(Code) | | Invalidates an object from the pool
By contract, obj MUST have been obtained
using
ObjectPool.borrowObject() borrowObject or a related method as defined in an implementation
or sub-interface.
This method should be used when an object that has been borrowed
is determined (due to an exception or other problem) to be invalid.
If the connection should be validated before or after borrowing,
then the
PoolableObjectFactory.validateObject method should be
used instead.
Parameters: obj - a ObjectPool.borrowObject borrowed instance to be returned. |
|
|