public class

CommonsPoolTargetSource

extends AbstractPoolingTargetSource
java.lang.Object
   ↳ org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
     ↳ org.springframework.aop.target.AbstractPrototypeBasedTargetSource
       ↳ org.springframework.aop.target.AbstractPoolingTargetSource
         ↳ org.springframework.aop.target.CommonsPoolTargetSource

Class Overview

TargetSource implementation that holds objects in a configurable Jakarta 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 explictly 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: for example,

Summary

[Expand]
Inherited Fields
From class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
Public Constructors
CommonsPoolTargetSource()
Create a CommonsPoolTargetSource with default settings.
Public Methods
void activateObject(Object obj)
void destroy()
Closes the underlying ObjectPool when destroying this object.
void destroyObject(Object obj)
int getActiveCount()
int getIdleCount()
int getMaxIdle()
Return the maximum number of idle objects in the pool.
long getMaxWait()
Return the maximum waiting time for fetching an object from the pool.
long getMinEvictableIdleTimeMillis()
Return the minimum time that an idle object can sit in the pool.
int getMinIdle()
Return the minimum number of idle objects in the pool.
Object getTarget()
Borrow an object from the ObjectPool.
long getTimeBetweenEvictionRunsMillis()
Return the time between eviction runs that check idle objects.
byte getWhenExhaustedAction()
Return the action to take when the pool is exhausted.
Object makeObject()
void passivateObject(Object obj)
void releaseTarget(Object target)
Returns the specified object to the underlying ObjectPool.
void setMaxIdle(int maxIdle)
Set the maximum number of idle objects in the pool.
void setMaxWait(long maxWait)
Set the maximum waiting time for fetching an object from the pool.
void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Set the minimum time that an idle object can sit in the pool before it becomes subject to eviction.
void setMinIdle(int minIdle)
Set the minimum number of idle objects in the pool.
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.
void setWhenExhaustedAction(byte whenExhaustedAction)
Set the action to take when the pool is exhausted.
void setWhenExhaustedActionName(String whenExhaustedActionName)
Set the action to take when the pool is exhausted.
boolean validateObject(Object obj)
Protected Methods
ObjectPool createObjectPool()
Subclasses can override this if they want to return a specific Commons pool.
final void createPool()
Creates and holds an ObjectPool instance.
[Expand]
Inherited Methods
From class org.springframework.aop.target.AbstractPoolingTargetSource
From class org.springframework.aop.target.AbstractPrototypeBasedTargetSource
From class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource
From class java.lang.Object
From interface org.springframework.aop.TargetClassAware
From interface org.springframework.aop.TargetSource
From interface org.springframework.aop.target.PoolingConfig
From interface org.springframework.beans.factory.BeanFactoryAware
From interface org.springframework.beans.factory.DisposableBean

Public Constructors

public CommonsPoolTargetSource ()

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

See Also

Public Methods

public void activateObject (Object obj)

public void destroy ()

Closes the underlying ObjectPool when destroying this object.

Throws
Exception

public void destroyObject (Object obj)

Throws
Exception

public int getActiveCount ()

public int getIdleCount ()

public int getMaxIdle ()

Return the maximum number of idle objects in the pool.

public long getMaxWait ()

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

public long getMinEvictableIdleTimeMillis ()

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

public int getMinIdle ()

Return the minimum number of idle objects in the pool.

public Object getTarget ()

Borrow an object from the ObjectPool.

Returns
  • an object from the pool
Throws
Exception

public long getTimeBetweenEvictionRunsMillis ()

Return the time between eviction runs that check idle objects.

public byte getWhenExhaustedAction ()

Return the action to take when the pool is exhausted.

public Object makeObject ()

public void passivateObject (Object obj)

public void releaseTarget (Object target)

Returns the specified object to the underlying ObjectPool.

Parameters
target object that must have been acquired from the pool via a call to getTarget()
Throws
Exception

public void setMaxIdle (int maxIdle)

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

See Also
  • GenericObjectPool#setMaxIdle

public void setMaxWait (long maxWait)

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

See Also
  • GenericObjectPool#setMaxWait

public 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

public void setMinIdle (int minIdle)

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

See Also
  • GenericObjectPool#setMinIdle

public 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
  • GenericObjectPool#setTimeBetweenEvictionRunsMillis

public void setWhenExhaustedAction (byte whenExhaustedAction)

Set the action to take when the pool is exhausted. Uses the constant values defined in Commons Pool's GenericObjectPool class.

See Also
  • GenericObjectPool#setWhenExhaustedAction(byte)
  • GenericObjectPool#WHEN_EXHAUSTED_BLOCK
  • GenericObjectPool#WHEN_EXHAUSTED_FAIL
  • GenericObjectPool#WHEN_EXHAUSTED_GROW

public void setWhenExhaustedActionName (String whenExhaustedActionName)

Set the action to take when the pool is exhausted. Uses the constant names defined in Commons Pool's GenericObjectPool class: "WHEN_EXHAUSTED_BLOCK", "WHEN_EXHAUSTED_FAIL", "WHEN_EXHAUSTED_GROW".

public boolean validateObject (Object obj)

Protected Methods

protected 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

protected final void createPool ()

Creates and holds an ObjectPool instance.