Package org.apache.commons.pool
Class PoolUtils.SynchronizedKeyedPoolableObjectFactory<K,V>
java.lang.Object
org.apache.commons.pool.PoolUtils.SynchronizedKeyedPoolableObjectFactory<K,V>
- All Implemented Interfaces:
KeyedPoolableObjectFactory<K,V>
- Enclosing class:
PoolUtils
private static class PoolUtils.SynchronizedKeyedPoolableObjectFactory<K,V>
extends Object
implements KeyedPoolableObjectFactory<K,V>
A fully synchronized KeyedPoolableObjectFactory that wraps a KeyedPoolableObjectFactory and synchronizes
access to the wrapped factory methods.
Note: This should not be used on pool implementations that already provide proper synchronization such as the pools provided in the Commons Pool library.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final KeyedPoolableObjectFactory<K, V> Wrapped factoryprivate final ObjectSynchronization lock -
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedKeyedPoolableObjectFactory(KeyedPoolableObjectFactory<K, V> keyedFactory) Create a SynchronizedKeyedPoolableObjectFactory wrapping the given factory. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateObject(K key, V obj) Reinitialize an instance to be returned by the pool.voiddestroyObject(K key, V obj) Destroy an instance no longer needed by the pool.makeObject(K key) Create an instance that can be served by the pool.voidpassivateObject(K key, V obj) Uninitialize an instance to be returned to the idle object pool.toString()booleanvalidateObject(K key, V obj) Ensures that the instance is safe to be returned by the pool.
-
Field Details
-
lock
Synchronization lock -
keyedFactory
Wrapped factory
-
-
Constructor Details
-
SynchronizedKeyedPoolableObjectFactory
SynchronizedKeyedPoolableObjectFactory(KeyedPoolableObjectFactory<K, V> keyedFactory) throws IllegalArgumentExceptionCreate a SynchronizedKeyedPoolableObjectFactory wrapping the given factory.- Parameters:
keyedFactory- underlying factory to wrap- Throws:
IllegalArgumentException- if the factory is null
-
-
Method Details
-
makeObject
Create an instance that can be served by the pool.- Specified by:
makeObjectin interfaceKeyedPoolableObjectFactory<K,V> - Parameters:
key- the key used when constructing the object- Returns:
- an instance that can be served by the pool.
- Throws:
Exception- if there is a problem creating a new instance, this will be propagated to the code requesting an object.
-
destroyObject
Destroy an instance no longer needed by the pool.It is important for implementations of this method to be aware that there is no guarantee about what state
objwill be in and the implementation should be prepared to handle unexpected errors.Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.
- Specified by:
destroyObjectin interfaceKeyedPoolableObjectFactory<K,V> - Parameters:
key- the key used when selecting the instanceobj- the instance to be destroyed- Throws:
Exception- should be avoided as it may be swallowed by the pool implementation.- See Also:
-
validateObject
Ensures that the instance is safe to be returned by the pool. Returnsfalseifobjshould be destroyed.- Specified by:
validateObjectin interfaceKeyedPoolableObjectFactory<K,V> - Parameters:
key- the key used when selecting the objectobj- the instance to be validated- Returns:
falseifobjis not valid and should be dropped from the pool,trueotherwise.
-
activateObject
Reinitialize an instance to be returned by the pool.- Specified by:
activateObjectin interfaceKeyedPoolableObjectFactory<K,V> - Parameters:
key- the key used when selecting the objectobj- the instance to be activated- Throws:
Exception- if there is a problem activatingobj, this exception may be swallowed by the pool.- See Also:
-
passivateObject
Uninitialize an instance to be returned to the idle object pool.- Specified by:
passivateObjectin interfaceKeyedPoolableObjectFactory<K,V> - Parameters:
key- the key used when selecting the objectobj- the instance to be passivated- Throws:
Exception- if there is a problem passivatingobj, this exception may be swallowed by the pool.- See Also:
-
toString
-