Class PoolUtils.SynchronizedPooledObjectFactory<T>
java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.pool2.PoolUtils.SynchronizedPooledObjectFactory<T>
- Type Parameters:
T- pooled object factory type
- All Implemented Interfaces:
PooledObjectFactory<T>
- Enclosing class:
PoolUtils
private static final class PoolUtils.SynchronizedPooledObjectFactory<T>
extends Object
implements PooledObjectFactory<T>
A fully synchronized PooledObjectFactory that wraps a
PooledObjectFactory 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.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PooledObjectFactory<T> Wrapped factoryprivate final ReentrantReadWriteLock.WriteLockSynchronization lock -
Constructor Summary
ConstructorsConstructorDescriptionCreates a SynchronizedPoolableObjectFactory wrapping the given factory. -
Method Summary
Modifier and TypeMethodDescriptionvoidReinitializes an instance to be returned by the pool.voidDestroys an instance no longer needed by the pool.Creates an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.voidUninitializes an instance to be returned to the idle object pool.toString()booleanEnsures that the instance is safe to be returned by the pool.
-
Field Details
-
writeLock
Synchronization lock -
factory
Wrapped factory
-
-
Constructor Details
-
SynchronizedPooledObjectFactory
SynchronizedPooledObjectFactory(PooledObjectFactory<T> factory) throws IllegalArgumentException Creates 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 and wrap it in aPooledObjectto be managed by the pool.- Specified by:
makeObjectin interfacePooledObjectFactory<T>- Returns:
- a
PooledObjectwrapping 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
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 interfacePooledObjectFactory<T>- Parameters:
p- aPooledObjectwrapping 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.- Specified by:
validateObjectin interfacePooledObjectFactory<T>- Parameters:
p- aPooledObjectwrapping the instance to be validated- Returns:
falseifobjis not valid and should be dropped from the pool,trueotherwise.
-
activateObject
Reinitializes an instance to be returned by the pool.- Specified by:
activateObjectin interfacePooledObjectFactory<T>- Parameters:
p- aPooledObjectwrapping the instance to be activated- Throws:
Exception- if there is a problem activatingobj, this exception may be swallowed by the pool.- See Also:
-
passivateObject
Uninitializes an instance to be returned to the idle object pool.- Specified by:
passivateObjectin interfacePooledObjectFactory<T>- Parameters:
p- aPooledObjectwrapping the instance to be passivated- Throws:
Exception- if there is a problem passivatingobj, this exception may be swallowed by the pool.- See Also:
-
toString
-