A keyed pool maintains a pool of instances for each key value.
Example of use:
Object obj =null; Object key ="Key";try{ obj = pool.borrowObject(key);//...use the object...}catch(Exception e) {// invalidate the objectpool.invalidateObject(key, 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(key, obj); } }
KeyedObjectPool implementations may choose to store at most
one instance per key value, or may choose to maintain a pool of instances
for each key (essentially creating a Map of
pools).
See GenericKeyedObjectPool for an implementation.
KeyedPooledObjectFactory, ObjectPool, GenericKeyedObjectPool
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public default void | addObjects(final Collection<K>
Collection of keys to add objects for.the number of idle objects to add for each count)key.Calls |
| public default void | addObjects(final K
the key to add objects for. key, final int the number of idle objects to add for count)key.Calls |
| public V | Returns: an instance from this pool.the key used to obtain the object key)Borrows an instance from this pool for the specified |
| public void | |
| public void | clear(K
the key to clear key)Clears the specified pool, removing all pooled instances corresponding to
the given |
| public void | close()
Redeclares java. Closes this pool, and free any resources associated with it. |
| public default List | |
| public int | Returns: the total number of instances currently borrowed from this pool but not yet returned.Gets the total number of instances currently borrowed from this pool but not yet returned. |
| public int | Returns: the number of instances currently borrowed from but not yet returned to the pool corresponding to the givenkey.the key to query key)Gets the number of instances currently borrowed from but not yet
returned to the pool corresponding to the given |
| public int | Returns: the total number of instances currently idle in this pool.Gets the total number of instances currently idle in this pool. |
| public int | Returns: the number of instances corresponding to the givenkey currently idle in this pool.the key to query key)Gets the number of instances corresponding to the given
|
| public void | invalidateObject(K
the key used to obtain the object key, V a obj)borrowed instance to be returned.Invalidates an object from the pool. |
| public default void | invalidateObject(final K
the key used to obtain the object key, final V a obj, final DestroyMode borrowed instance to be returned.destroy activation context provided to the factory destroyMode)Invalidates an object from the pool, using the provided
|
| public void | returnObject(K
the key used to obtain the object key, V a obj)borrowed instance to be returned.Return an instance to the pool. |
| addObject | back to summary |
|---|---|
| public void addObject(K key) throws Exception Creates an object using the
| |
| addObjects | back to summary |
|---|---|
| public default void addObjects(final Collection<K> keys, final int count) throws Exception Calls
| |
| addObjects | back to summary |
|---|---|
| public default void addObjects(final K key, final int count) throws Exception Calls
| |
| borrowObject | back to summary |
|---|---|
| public V borrowObject(K key) throws Exception Borrows an instance from this pool for the specified
Instances returned from this method will have been either newly created
with
By contract, clients must return the borrowed object
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 the pool, removing all pooled instances (optional operation).
| |
| clear | back to summary |
|---|---|
| public void clear(K key) throws Exception Clears the specified pool, removing all pooled instances corresponding to
the given
| |
| 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.
| |
| getKeys | back to summary |
|---|---|
| public default List Gets a copy of the pool key list. Note The default implementation returns an empty list. Implementations should override this method.
| |
| getNumActive | back to summary |
|---|---|
| public int getNumActive() Gets the total number of instances currently borrowed from this pool but not yet returned. Returns a negative value if this information is not available.
| |
| getNumActive | back to summary |
|---|---|
| public int getNumActive(K key) Gets the number of instances currently borrowed from but not yet
returned to the pool corresponding to the given
| |
| getNumIdle | back to summary |
|---|---|
| public int getNumIdle() Gets the total number of instances currently idle in this pool. Returns a negative value if this information is not available.
| |
| getNumIdle | back to summary |
|---|---|
| public int getNumIdle(K key) Gets the number of instances corresponding to the given
| |
| invalidateObject | back to summary |
|---|---|
| public void invalidateObject(K key, V 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 K key, final V 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(K key, V obj) throws Exception Return an instance to the pool. By contract,
| |