Example of use:
Object obj =null;try{ obj = pool.borrowObject();try{//...use the object...}catch(Exception e) {// invalidate the objectpool.invalidateObject(obj);// do not return the object to the pool twiceobj =null; }finally{// make sure the object is returned to the poolif(null!= obj) { pool.returnObject(obj); } } }catch(Exception e) {// failed to borrow an object}
See BaseObjectPool for a simple base implementation.
PooledObjectFactory, KeyedObjectPool, BaseObjectPool
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public default void | addObjects(final int
the number of idle objects to add. count)Calls |
| public T | |
| public void | clear()
Clears any objects sitting idle in the pool, releasing any associated resources (optional operation). |
| public void | close()
Redeclares java. Closes this pool, and free any resources associated with it. |
| public int | Returns: the number of instances currently borrowed from this pool.Gets the number of instances currently borrowed from this pool. |
| public int | Returns: the number of instances currently idle in this pool.Gets the number of instances currently idle in this pool. |
| public void | |
| public default void | invalidateObject(final T
a obj, final DestroyMode borrowed instance to be disposed.destroy activation context provided to the factory destroyMode)Invalidates an object from the pool, using the provided
By contract, |
| public void |
| addObject | back to summary |
|---|---|
| public void addObject() throws Exception Creates an object using the
| |
| addObjects | back to summary |
|---|---|
| public default void addObjects(final int count) throws Exception Calls
| |
| borrowObject | back to summary |
|---|---|
| public T borrowObject() throws Exception Borrows an instance from this pool.
Instances returned from this method will have been either newly created
with
By contract, clients must return the borrowed instance
using The behavior of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations).
| |
| clear | back to summary |
|---|---|
| public void clear() throws Exception Clears any objects sitting idle in the pool, releasing any associated
resources (optional operation). Idle objects cleared must be
| |
| close | back to summary |
|---|---|
| public void close() Redeclares java. Closes this pool, and free any resources associated with it.
Calling Implementations should silently fail if not all resources can be freed.
| |
| getNumActive | back to summary |
|---|---|
| public int getNumActive() Gets the number of instances currently borrowed from this pool. Returns a negative value if this information is not available.
| |
| getNumIdle | back to summary |
|---|---|
| public int getNumIdle() Gets the number of instances currently idle in this pool. This may be
considered an approximation of the number of objects that can be
| |
| invalidateObject | back to summary |
|---|---|
| public void invalidateObject(T obj) throws Exception Invalidates an object from the pool.
By contract, This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid. | |
| invalidateObject | back to summary |
|---|---|
| public default void invalidateObject(final T obj, final DestroyMode destroyMode) throws Exception Invalidates an object from the pool, using the provided
By contract, This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
| |
| returnObject | back to summary |
|---|---|
| public void returnObject(T obj) throws Exception Returns an instance to the pool. By contract,
| |