private static class PoolUtils.SynchronizedPooledObjectFactory<T> extends java.lang.Object implements PooledObjectFactory<T>
Note: This should not be used on pool implementations that already provide proper synchronization such as the pools provided in the Commons Pool library.
| Modifier and Type | Field and Description |
|---|---|
private PooledObjectFactory<T> |
factory
Wrapped factory
|
private java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
writeLock
Synchronization lock
|
| Constructor and Description |
|---|
SynchronizedPooledObjectFactory(PooledObjectFactory<T> factory)
Create a SynchronizedPoolableObjectFactory wrapping the given
factory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(PooledObject<T> p)
Reinitialize an instance to be returned by the pool.
|
void |
destroyObject(PooledObject<T> p)
Destroys an instance no longer needed by the pool.
|
PooledObject<T> |
makeObject()
Create an instance that can be served by the pool and wrap it in a
PooledObject to be managed by the pool. |
void |
passivateObject(PooledObject<T> p)
Uninitialize an instance to be returned to the idle object pool.
|
java.lang.String |
toString() |
boolean |
validateObject(PooledObject<T> p)
Ensures that the instance is safe to be returned by the pool.
|
private final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock writeLock
private final PooledObjectFactory<T> factory
SynchronizedPooledObjectFactory(PooledObjectFactory<T> factory) throws java.lang.IllegalArgumentException
factory - underlying factory to wrapjava.lang.IllegalArgumentException - if the factory is nullpublic PooledObject<T> makeObject() throws java.lang.Exception
PooledObject to be managed by the pool.makeObject in interface PooledObjectFactory<T>PooledObject wrapping an instance that can be served by the pooljava.lang.Exception - if there is a problem creating a new instance,
this will be propagated to the code requesting an object.public void destroyObject(PooledObject<T> p) throws java.lang.Exception
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.
destroyObject in interface PooledObjectFactory<T>p - a PooledObject wrapping the instance to be destroyedjava.lang.Exception - should be avoided as it may be swallowed by
the pool implementation.PooledObjectFactory.validateObject(org.apache.commons.pool2.PooledObject<T>),
ObjectPool.invalidateObject(T)public boolean validateObject(PooledObject<T> p)
validateObject in interface PooledObjectFactory<T>p - a PooledObject wrapping the instance to be validatedfalse if obj is not valid and should
be dropped from the pool, true otherwise.public void activateObject(PooledObject<T> p) throws java.lang.Exception
activateObject in interface PooledObjectFactory<T>p - a PooledObject wrapping the instance to be activatedjava.lang.Exception - if there is a problem activating obj,
this exception may be swallowed by the pool.PooledObjectFactory.destroyObject(org.apache.commons.pool2.PooledObject<T>)public void passivateObject(PooledObject<T> p) throws java.lang.Exception
passivateObject in interface PooledObjectFactory<T>p - a PooledObject wrapping the instance to be passivatedjava.lang.Exception - if there is a problem passivating obj,
this exception may be swallowed by the pool.PooledObjectFactory.destroyObject(org.apache.commons.pool2.PooledObject<T>)public java.lang.String toString()
toString in class java.lang.Object