CommonsPool2TargetSource@Deprecated public class CommonsPoolTargetSource extends AbstractPoolingTargetSource
TargetSource implementation that holds
objects in a configurable Apache Commons Pool.
By default, an instance of GenericObjectPool is created.
Subclasses may change the type of ObjectPool used by
overriding the createObjectPool() method.
Provides many configuration properties mirroring those of the Commons Pool
GenericObjectPool class; these properties are passed to the
GenericObjectPool during construction. If creating a subclass of this
class to change the ObjectPool implementation type, pass in the values
of configuration properties that are relevant to your chosen implementation.
The testOnBorrow, testOnReturn and testWhileIdle
properties are explicitly not mirrored because the implementation of
PoolableObjectFactory used by this class does not implement
meaningful validation. All exposed Commons Pool properties use the
corresponding Commons Pool defaults.
Compatible with Apache Commons Pool 1.5.x and 1.6. Note that this class doesn't declare Commons Pool 1.6's generic type in order to remain compatible with Commons Pool 1.5.x at runtime.
GenericObjectPool,
createObjectPool(),
AbstractPoolingTargetSource.setMaxSize(int),
setMaxIdle(int),
setMinIdle(int),
setMaxWait(long),
setTimeBetweenEvictionRunsMillis(long),
setMinEvictableIdleTimeMillis(long),
Serialized Form| Modifier and Type | Field and Description |
|---|---|
private static Constants |
constants
Deprecated.
|
private int |
maxIdle
Deprecated.
|
private long |
maxWait
Deprecated.
|
private long |
minEvictableIdleTimeMillis
Deprecated.
|
private int |
minIdle
Deprecated.
|
private ObjectPool |
pool
Deprecated.
The Apache Commons
ObjectPool used to pool target objects |
private long |
timeBetweenEvictionRunsMillis
Deprecated.
|
private byte |
whenExhaustedAction
Deprecated.
|
logger| Constructor and Description |
|---|
CommonsPoolTargetSource()
Deprecated.
Create a CommonsPoolTargetSource with default settings.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(java.lang.Object obj)
Deprecated.
|
protected ObjectPool |
createObjectPool()
Deprecated.
Subclasses can override this if they want to return a specific Commons pool.
|
protected void |
createPool()
Deprecated.
Creates and holds an ObjectPool instance.
|
void |
destroy()
Deprecated.
Closes the underlying
ObjectPool when destroying this object. |
void |
destroyObject(java.lang.Object obj)
Deprecated.
|
int |
getActiveCount()
Deprecated.
Return the number of active objects in the pool.
|
int |
getIdleCount()
Deprecated.
Return the number of idle objects in the pool.
|
int |
getMaxIdle()
Deprecated.
Return the maximum number of idle objects in the pool.
|
long |
getMaxWait()
Deprecated.
Return the maximum waiting time for fetching an object from the pool.
|
long |
getMinEvictableIdleTimeMillis()
Deprecated.
Return the minimum time that an idle object can sit in the pool.
|
int |
getMinIdle()
Deprecated.
Return the minimum number of idle objects in the pool.
|
java.lang.Object |
getTarget()
Deprecated.
Borrow an object from the
ObjectPool. |
long |
getTimeBetweenEvictionRunsMillis()
Deprecated.
Return the time between eviction runs that check idle objects.
|
byte |
getWhenExhaustedAction()
Deprecated.
Return the action to take when the pool is exhausted.
|
java.lang.Object |
makeObject()
Deprecated.
|
void |
passivateObject(java.lang.Object obj)
Deprecated.
|
void |
releaseTarget(java.lang.Object target)
Deprecated.
Returns the specified object to the underlying
ObjectPool. |
void |
setMaxIdle(int maxIdle)
Deprecated.
Set the maximum number of idle objects in the pool.
|
void |
setMaxWait(long maxWait)
Deprecated.
Set the maximum waiting time for fetching an object from the pool.
|
void |
setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Deprecated.
Set the minimum time that an idle object can sit in the pool before
it becomes subject to eviction.
|
void |
setMinIdle(int minIdle)
Deprecated.
Set the minimum number of idle objects in the pool.
|
void |
setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Deprecated.
Set the time between eviction runs that check idle objects whether
they have been idle for too long or have become invalid.
|
void |
setWhenExhaustedAction(byte whenExhaustedAction)
Deprecated.
Set the action to take when the pool is exhausted.
|
void |
setWhenExhaustedActionName(java.lang.String whenExhaustedActionName)
Deprecated.
Set the action to take when the pool is exhausted.
|
boolean |
validateObject(java.lang.Object obj)
Deprecated.
|
getMaxSize, getPoolingConfigMixin, setBeanFactory, setMaxSizedestroyPrototypeInstance, newPrototypeInstance, writeReplacecopyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, setTargetBeanName, setTargetClass, toStringprivate static final Constants constants
private int maxIdle
private int minIdle
private long maxWait
private long timeBetweenEvictionRunsMillis
private long minEvictableIdleTimeMillis
private byte whenExhaustedAction
private ObjectPool pool
ObjectPool used to pool target objectspublic CommonsPoolTargetSource()
AbstractPoolingTargetSource.setMaxSize(int),
GenericObjectPool#setMaxActivepublic void setMaxIdle(int maxIdle)
GenericObjectPool#setMaxIdlepublic int getMaxIdle()
public void setMinIdle(int minIdle)
GenericObjectPool#setMinIdlepublic int getMinIdle()
public void setMaxWait(long maxWait)
GenericObjectPool#setMaxWaitpublic long getMaxWait()
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
GenericObjectPool#setTimeBetweenEvictionRunsMillispublic long getTimeBetweenEvictionRunsMillis()
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Note that eviction runs need to be performed to take this setting into effect.
setTimeBetweenEvictionRunsMillis(long),
GenericObjectPool#setMinEvictableIdleTimeMillispublic long getMinEvictableIdleTimeMillis()
public void setWhenExhaustedActionName(java.lang.String whenExhaustedActionName)
setWhenExhaustedAction(byte)public void setWhenExhaustedAction(byte whenExhaustedAction)
GenericObjectPool#setWhenExhaustedAction(byte),
GenericObjectPool#WHEN_EXHAUSTED_BLOCK,
GenericObjectPool#WHEN_EXHAUSTED_FAIL,
GenericObjectPool#WHEN_EXHAUSTED_GROWpublic byte getWhenExhaustedAction()
protected final void createPool()
createPool in class AbstractPoolingTargetSourcecreateObjectPool()protected ObjectPool createObjectPool()
Default is a GenericObjectPool instance with the given pool size.
ObjectPool.org.apache.commons.pool.impl.GenericObjectPool,
AbstractPoolingTargetSource.setMaxSize(int)public java.lang.Object getTarget()
throws java.lang.Exception
ObjectPool.getTarget in interface TargetSourcegetTarget in class AbstractPoolingTargetSourcejava.lang.Exception - we may need to deal with checked exceptions from pool
APIs, so we're forgiving with our exception signaturepublic void releaseTarget(java.lang.Object target)
throws java.lang.Exception
ObjectPool.releaseTarget in interface TargetSourcereleaseTarget in class AbstractPoolingTargetSourcetarget - object that must have been acquired from the pool
via a call to getTarget()java.lang.Exception - to allow pooling APIs to throw exceptionAbstractPoolingTargetSource.getTarget()public int getActiveCount()
throws java.lang.UnsupportedOperationException
PoolingConfigjava.lang.UnsupportedOperationException - if not supported by the poolpublic int getIdleCount()
throws java.lang.UnsupportedOperationException
PoolingConfigjava.lang.UnsupportedOperationException - if not supported by the poolpublic void destroy()
throws java.lang.Exception
ObjectPool when destroying this object.java.lang.Exception - in case of shutdown errors.
Exceptions will get logged but not rethrown to allow
other beans to release their resources too.public java.lang.Object makeObject()
throws BeansException
BeansExceptionpublic void destroyObject(java.lang.Object obj)
throws java.lang.Exception
java.lang.Exceptionpublic boolean validateObject(java.lang.Object obj)
public void activateObject(java.lang.Object obj)
public void passivateObject(java.lang.Object obj)