Package org.apache.commons.pool
Class PoolUtils.SynchronizedPoolableObjectFactory<T>
java.lang.Object
org.apache.commons.pool.PoolUtils.SynchronizedPoolableObjectFactory<T>
- All Implemented Interfaces:
PoolableObjectFactory<T>
- Enclosing class:
PoolUtils
private static class PoolUtils.SynchronizedPoolableObjectFactory<T>
extends Object
implements PoolableObjectFactory<T>
A fully synchronized PoolableObjectFactory that wraps a PoolableObjectFactory 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 PoolableObjectFactory
<T> Wrapped factoryprivate final Object
Synchronization lock -
Constructor Summary
ConstructorsConstructorDescriptionCreate a SynchronizedPoolableObjectFactory wrapping the given factory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activateObject
(T obj) Reinitialize an instance to be returned by the pool.void
destroyObject
(T obj) Destroys an instance no longer needed by the pool.Creates an instance that can be served by the pool.void
passivateObject
(T obj) Uninitialize an instance to be returned to the idle object pool.toString()
boolean
validateObject
(T obj) Ensures that the instance is safe to be returned by the pool.
-
Field Details
-
lock
Synchronization lock -
factory
Wrapped factory
-
-
Constructor Details
-
SynchronizedPoolableObjectFactory
SynchronizedPoolableObjectFactory(PoolableObjectFactory<T> factory) throws IllegalArgumentException Create a SynchronizedPoolableObjectFactory wrapping the given factory.- Parameters:
factory
- underlying factory to wrap- Throws:
IllegalArgumentException
- if the factory is null
-
-
Method Details
-
makeObject
Creates an instance that can be served by the pool. Instances returned from this method should be in the same state as if they had beenactivated
. They will not be activated before being served by the pool.- Specified by:
makeObject
in interfacePoolableObjectFactory<T>
- 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
Destroys 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
obj
will 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:
destroyObject
in interfacePoolableObjectFactory<T>
- Parameters:
obj
- 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. Returnsfalse
ifobj
should be destroyed.- Specified by:
validateObject
in interfacePoolableObjectFactory<T>
- Parameters:
obj
- the instance to be validated- Returns:
false
ifobj
is not valid and should be dropped from the pool,true
otherwise.
-
activateObject
Reinitialize an instance to be returned by the pool.- Specified by:
activateObject
in interfacePoolableObjectFactory<T>
- Parameters:
obj
- 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:
passivateObject
in interfacePoolableObjectFactory<T>
- Parameters:
obj
- the instance to be passivated- Throws:
Exception
- if there is a problem passivatingobj
, this exception may be swallowed by the pool.- See Also:
-
toString
-