spring-framework / org.springframework.aop.target / CommonsPool2TargetSource

CommonsPool2TargetSource

open class CommonsPool2TargetSource : AbstractPoolingTargetSource, PooledObjectFactory<Any>

org.springframework.aop.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.

Author
Rod Johnson

Author
Rob Harrop

Author
Juergen Hoeller

Author
Stephane Nicoll

Author
Kazuki Shimizu

Since
4.2

See Also
GenericObjectPool#createObjectPool()#setMaxSize#setMaxIdle#setMinIdle#setMaxWait#setTimeBetweenEvictionRunsMillis#setMinEvictableIdleTimeMillis

Constructors

<init>

CommonsPool2TargetSource()

Create a CommonsPoolTargetSource with default settings. Default maximum size of the pool is 8.

Functions

activateObject

open fun activateObject(p: PooledObject<Any>): Unit

destroy

open fun destroy(): Unit

Closes the underlying ObjectPool when destroying this object.

destroyObject

open fun destroyObject(p: PooledObject<Any>): Unit

getActiveCount

open fun getActiveCount(): Int

getIdleCount

open fun getIdleCount(): Int

getMaxIdle

open fun getMaxIdle(): Int

Return the maximum number of idle objects in the pool.

getMaxWait

open fun getMaxWait(): Long

Return the maximum waiting time for fetching an object from the pool.

getMinEvictableIdleTimeMillis

open fun getMinEvictableIdleTimeMillis(): Long

Return the minimum time that an idle object can sit in the pool.

getMinIdle

open fun getMinIdle(): Int

Return the minimum number of idle objects in the pool.

getTarget

open fun getTarget(): Any

Borrows an object from the ObjectPool.

getTimeBetweenEvictionRunsMillis

open fun getTimeBetweenEvictionRunsMillis(): Long

Return the time between eviction runs that check idle objects.

isBlockWhenExhausted

open fun isBlockWhenExhausted(): Boolean

Specify if the call should block when the pool is exhausted.

makeObject

open fun makeObject(): PooledObject<Any>

passivateObject

open fun passivateObject(p: PooledObject<Any>): Unit

releaseTarget

open fun releaseTarget(target: Any): Unit

Returns the specified object to the underlying ObjectPool.

setBlockWhenExhausted

open fun setBlockWhenExhausted(blockWhenExhausted: Boolean): Unit

Set whether the call should bock when the pool is exhausted.

setMaxIdle

open fun setMaxIdle(maxIdle: Int): Unit

Set the maximum number of idle objects in the pool. Default is 8.

setMaxWait

open fun setMaxWait(maxWait: Long): Unit

Set the maximum waiting time for fetching an object from the pool. Default is -1, waiting forever.

setMinEvictableIdleTimeMillis

open fun setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis: Long): Unit

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.

setMinIdle

open fun setMinIdle(minIdle: Int): Unit

Set the minimum number of idle objects in the pool. Default is 0.

setTimeBetweenEvictionRunsMillis

open fun setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis: Long): Unit

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.

validateObject

open fun validateObject(p: PooledObject<Any>): Boolean