Class CommonsPool2TargetSource
- All Implemented Interfaces:
- Serializable,- org.apache.commons.pool2.PooledObjectFactory<Object>,- PoolingConfig,- TargetClassAware,- TargetSource,- Aware,- BeanFactoryAware,- DisposableBean
TargetSource implementation that holds
 objects in a configurable Apache Commons2 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 2.4, as of Spring 4.2.
- Since:
- 4.2
- Author:
- Rod Johnson, Rob Harrop, Juergen Hoeller, Stephane Nicoll, Kazuki Shimizu
- See Also:
- 
Field SummaryFields inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSourcelogger
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a CommonsPoolTargetSource with default settings.
- 
Method SummaryModifier and TypeMethodDescriptionvoidactivateObject(org.apache.commons.pool2.PooledObject<Object> p) protected org.apache.commons.pool2.ObjectPoolSubclasses can override this if they want to return a specific Commons pool.protected final voidCreates and holds an ObjectPool instance.voiddestroy()Closes the underlyingObjectPoolwhen destroying this object.voiddestroyObject(org.apache.commons.pool2.PooledObject<Object> p) intReturn the number of active objects in the pool.intReturn the number of idle objects in the pool.intReturn the maximum number of idle objects in the pool.longReturn the maximum waiting time for fetching an object from the pool.longReturn the minimum time that an idle object can sit in the pool.intReturn the minimum number of idle objects in the pool.Borrows an object from theObjectPool.longReturn the time between eviction runs that check idle objects.booleanSpecify if the call should block when the pool is exhausted.org.apache.commons.pool2.PooledObject<Object>voidpassivateObject(org.apache.commons.pool2.PooledObject<Object> p) voidreleaseTarget(Object target) Returns the specified object to the underlyingObjectPool.voidsetBlockWhenExhausted(boolean blockWhenExhausted) Set whether the call should block when the pool is exhausted.voidsetMaxIdle(int maxIdle) Set the maximum number of idle objects in the pool.voidsetMaxWait(long maxWait) Set the maximum waiting time for fetching an object from the pool.voidsetMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Set the minimum time that an idle object can sit in the pool before it becomes subject to eviction.voidsetMinIdle(int minIdle) Set the minimum number of idle objects in the pool.voidsetTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Set the time between eviction runs that check idle objects whether they have been idle for too long or have become invalid.booleanvalidateObject(org.apache.commons.pool2.PooledObject<Object> p) Methods inherited from class org.springframework.aop.target.AbstractPoolingTargetSourcegetMaxSize, getPoolingConfigMixin, setBeanFactory, setMaxSizeMethods inherited from class org.springframework.aop.target.AbstractPrototypeBasedTargetSourcedestroyPrototypeInstance, newPrototypeInstance, writeReplaceMethods inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSourcecopyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, setTargetBeanName, setTargetClass, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.pool2.PooledObjectFactorydestroyObjectMethods inherited from interface org.springframework.aop.TargetSourceisStatic
- 
Constructor Details- 
CommonsPool2TargetSourcepublic CommonsPool2TargetSource()Create a CommonsPoolTargetSource with default settings. Default maximum size of the pool is 8.- See Also:
- 
- AbstractPoolingTargetSource.setMaxSize(int)
- GenericObjectPoolConfig.setMaxTotal(int)
 
 
 
- 
- 
Method Details- 
setMaxIdlepublic void setMaxIdle(int maxIdle) Set the maximum number of idle objects in the pool. Default is 8.- See Also:
- 
- GenericObjectPool.setMaxIdle(int)
 
 
- 
getMaxIdlepublic int getMaxIdle()Return the maximum number of idle objects in the pool.
- 
setMinIdlepublic void setMinIdle(int minIdle) Set the minimum number of idle objects in the pool. Default is 0.- See Also:
- 
- GenericObjectPool.setMinIdle(int)
 
 
- 
getMinIdlepublic int getMinIdle()Return the minimum number of idle objects in the pool.
- 
setMaxWaitpublic void setMaxWait(long maxWait) Set the maximum waiting time for fetching an object from the pool. Default is -1, waiting forever.- See Also:
- 
- BaseGenericObjectPool.setMaxWaitMillis(long)
 
 
- 
getMaxWaitpublic long getMaxWait()Return the maximum waiting time for fetching an object from the pool.
- 
setTimeBetweenEvictionRunsMillispublic void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Set the time between eviction runs that check idle objects whether they have been idle for too long or have become invalid. Default is -1, not performing any eviction.- See Also:
- 
- BaseGenericObjectPool.setTimeBetweenEvictionRunsMillis(long)
 
 
- 
getTimeBetweenEvictionRunsMillispublic long getTimeBetweenEvictionRunsMillis()Return the time between eviction runs that check idle objects.
- 
setMinEvictableIdleTimeMillispublic void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) Set the minimum time that an idle object can sit in the pool before it becomes subject to eviction. Default is 1800000 (30 minutes).Note that eviction runs need to be performed to take this setting into effect. - See Also:
- 
- setTimeBetweenEvictionRunsMillis(long)
- BaseGenericObjectPool.setMinEvictableIdleTimeMillis(long)
 
 
- 
getMinEvictableIdleTimeMillispublic long getMinEvictableIdleTimeMillis()Return the minimum time that an idle object can sit in the pool.
- 
setBlockWhenExhaustedpublic void setBlockWhenExhausted(boolean blockWhenExhausted) Set whether the call should block when the pool is exhausted.
- 
isBlockWhenExhaustedpublic boolean isBlockWhenExhausted()Specify if the call should block when the pool is exhausted.
- 
createPoolprotected final void createPool()Creates and holds an ObjectPool instance.- Specified by:
- createPoolin class- AbstractPoolingTargetSource
- See Also:
 
- 
createObjectPoolprotected org.apache.commons.pool2.ObjectPool createObjectPool()Subclasses can override this if they want to return a specific Commons pool. They should apply any configuration properties to the pool here.Default is a GenericObjectPool instance with the given pool size. - Returns:
- an empty Commons ObjectPool.
- See Also:
- 
- GenericObjectPool
- AbstractPoolingTargetSource.setMaxSize(int)
 
 
- 
getTargetBorrows an object from theObjectPool.- Specified by:
- getTargetin interface- TargetSource
- Specified by:
- getTargetin class- AbstractPoolingTargetSource
- Returns:
- an object from the pool
- Throws:
- Exception- we may need to deal with checked exceptions from pool APIs, so we're forgiving with our exception signature
 
- 
releaseTargetReturns the specified object to the underlyingObjectPool.- Specified by:
- releaseTargetin interface- TargetSource
- Specified by:
- releaseTargetin class- AbstractPoolingTargetSource
- Parameters:
- target- object that must have been acquired from the pool via a call to- getTarget()
- Throws:
- Exception- to allow pooling APIs to throw exception
- See Also:
 
- 
getActiveCountDescription copied from interface:PoolingConfigReturn the number of active objects in the pool.- Specified by:
- getActiveCountin interface- PoolingConfig
- Throws:
- UnsupportedOperationException- if not supported by the pool
 
- 
getIdleCountDescription copied from interface:PoolingConfigReturn the number of idle objects in the pool.- Specified by:
- getIdleCountin interface- PoolingConfig
- Throws:
- UnsupportedOperationException- if not supported by the pool
 
- 
destroyCloses the underlyingObjectPoolwhen destroying this object.- Specified by:
- destroyin interface- DisposableBean
- Throws:
- Exception- in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources as well.
 
- 
makeObject
- 
destroyObject
- 
validateObject- Specified by:
- validateObjectin interface- org.apache.commons.pool2.PooledObjectFactory<Object>
 
- 
activateObject
- 
passivateObject
 
-