|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ObjectPool
A pooling interface.
ObjectPool
defines a trivially simple pooling interface. The only
required methods are borrowObject
and 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); } } |
BaseObjectPool
for a simple base implementation.
Method Summary | |
---|---|
void |
addObject()
Create an object using my factory or other
implementation dependent mechanism, and place it into the pool. |
java.lang.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(java.lang.Object obj)
Invalidates an object from the pool By contract, obj MUST have been obtained using borrowObject
or a related method as defined in an implementation
or sub-interface. |
void |
returnObject(java.lang.Object obj)
Return an instance to my pool. |
void |
setFactory(PoolableObjectFactory factory)
Sets the factory I use
to create new instances (optional operation). |
Method Detail |
---|
void addObject() throws java.lang.Exception
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).
java.lang.Exception
java.lang.Object borrowObject() throws java.lang.Exception
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).
java.lang.Exception
void clear() throws java.lang.Exception, java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
- if this implementation does not support the operation
java.lang.Exception
void close() throws java.lang.Exception
java.lang.Exception
int getNumActive() throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
- if this implementation does not support the operationint getNumIdle() throws java.lang.UnsupportedOperationException
borrowed
without creating any new instances.
java.lang.UnsupportedOperationException
- if this implementation does not support the operationvoid invalidateObject(java.lang.Object obj) throws java.lang.Exception
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(java.lang.Object)
method should be
used instead.
obj
- a borrowed
instance to be returned.
java.lang.Exception
void returnObject(java.lang.Object obj) throws java.lang.Exception
borrowObject
or a related method as defined in an implementation
or sub-interface.
obj
- a borrowed
instance to be returned.
java.lang.Exception
void setFactory(PoolableObjectFactory factory) throws java.lang.IllegalStateException, java.lang.UnsupportedOperationException
factory
I use
to create new instances (optional operation).
factory
- the PoolableObjectFactory
I use to create new instances.
java.lang.IllegalStateException
- when the factory cannot be set at this time
java.lang.UnsupportedOperationException
- if this implementation does not support the operation
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |