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.
GenericObjectPool, createObjectPool(), setMaxSize, setMaxIdle, setMinIdle, setMaxWait, setTimeBetweenEvictionRunsMillis, setMinEvictableIdleTimeMillis
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private int | |
| private long | |
| private long | |
| private int | |
| private ObjectPool | pool
The Apache Commons |
| private long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | activateObject(PooledObject<Object>
a p)PooledObject wrapping the instance to be activatedImplements org. Reinitializes an instance to be returned by the pool. |
| protected ObjectPool | Returns: an empty CommonsObjectPool.Subclasses can override this if they want to return a specific Commons pool. |
| protected final void | createPool()
Implements abstract org. Creates and holds an ObjectPool instance. |
| public void | destroy()
Implements org. Closes the underlying |
| public void | destroyObject(PooledObject<Object>
a p)PooledObject wrapping the instance to be destroyedImplements org. Destroys an instance no longer needed by the pool, using the default (NORMAL) DestroyMode. |
| public int | getActiveCount()
Implements org. Return the number of active objects in the pool. |
| public int | getIdleCount()
Implements org. Return the number of idle objects in the pool. |
| public int | |
| public long | |
| public long | |
| public int | |
| public Object | getTarget()
Implements abstract org. Implements org. Borrows an object from the |
| public long | |
| public boolean | |
| public PooledObject | makeObject()
Implements org. Creates an instance that can be served by the pool and wrap it in a
|
| public void | passivateObject(PooledObject<Object>
a p)PooledObject wrapping the instance to be passivatedImplements org. Uninitializes an instance to be returned to the idle object pool. |
| public void | releaseTarget(Object
object that must have been acquired from the pool
via a call to target)getTarget()Overrides default org. Implements abstract org. Returns the specified object to the underlying |
| public void | setBlockWhenExhausted(boolean blockWhenExhausted)
Set whether the call should block when the pool is exhausted. |
| public void | |
| public void | |
| public void | setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Set the minimum time that an idle object can sit in the pool before it becomes subject to eviction. |
| public void | |
| 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. |
| public boolean | validateObject(PooledObject<Object>
a p)PooledObject wrapping the instance to be validatedImplements org. Ensures that the instance is safe to be returned by the pool. |
| blockWhenExhausted | back to summary |
|---|---|
| private boolean blockWhenExhausted | |
| maxIdle | back to summary |
|---|---|
| private int maxIdle | |
| maxWait | back to summary |
|---|---|
| private long maxWait | |
| minEvictableIdleTimeMillis | back to summary |
|---|---|
| private long minEvictableIdleTimeMillis | |
| minIdle | back to summary |
|---|---|
| private int minIdle | |
| pool | back to summary |
|---|---|
| private ObjectPool<T> pool The Apache Commons | |
| timeBetweenEvictionRunsMillis | back to summary |
|---|---|
| private long timeBetweenEvictionRunsMillis | |
| CommonsPool2TargetSource | back to summary |
|---|---|
| public CommonsPool2TargetSource() Create a CommonsPoolTargetSource with default settings. Default maximum size of the pool is 8. | |
| activateObject | back to summary |
|---|---|
| public void activateObject(PooledObject<Object> p) throws Exception Implements org. Doc from org. Reinitializes an instance to be returned by the pool.
| |
| createObjectPool | back to summary |
|---|---|
| protected ObjectPool 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.
| |
| createPool | back to summary |
|---|---|
| protected final void createPool() Implements abstract org. Creates and holds an ObjectPool instance.
| |
| destroy | back to summary |
|---|---|
| public void destroy() throws Exception Implements org. Closes the underlying
| |
| destroyObject | back to summary |
|---|---|
| public void destroyObject(PooledObject<Object> p) throws Exception Implements org. Doc from org. Destroys an instance no longer needed by the pool, using the default (NORMAL) DestroyMode.
It is important for implementations of this method to be aware that there
is no guarantee about what state Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.
| |
| getActiveCount | back to summary |
|---|---|
| public int getActiveCount() throws UnsupportedOperationException Implements org. Doc from org. Return the number of active objects in the pool.
| |
| getIdleCount | back to summary |
|---|---|
| public int getIdleCount() throws UnsupportedOperationException Implements org. Doc from org. Return the number of idle objects in the pool.
| |
| getMaxIdle | back to summary |
|---|---|
| public int getMaxIdle() Return the maximum number of idle objects in the pool. | |
| getMaxWait | back to summary |
|---|---|
| public long getMaxWait() Return the maximum waiting time for fetching an object from the pool. | |
| getMinEvictableIdleTimeMillis | back to summary |
|---|---|
| public long getMinEvictableIdleTimeMillis() Return the minimum time that an idle object can sit in the pool. | |
| getMinIdle | back to summary |
|---|---|
| public int getMinIdle() Return the minimum number of idle objects in the pool. | |
| getTarget | back to summary |
|---|---|
| public Object getTarget() throws Exception Implements abstract org. Implements org. Borrows an object from the
| |
| getTimeBetweenEvictionRunsMillis | back to summary |
|---|---|
| public long getTimeBetweenEvictionRunsMillis() Return the time between eviction runs that check idle objects. | |
| isBlockWhenExhausted | back to summary |
|---|---|
| public boolean isBlockWhenExhausted() Specify if the call should block when the pool is exhausted. | |
| makeObject | back to summary |
|---|---|
| public PooledObject Implements org. Doc from org. Creates an instance that can be served by the pool and wrap it in a
| |
| passivateObject | back to summary |
|---|---|
| public void passivateObject(PooledObject<Object> p) throws Exception Implements org. Doc from org. Uninitializes an instance to be returned to the idle object pool.
| |
| releaseTarget | back to summary |
|---|---|
| public void releaseTarget(Object target) throws Exception Overrides default org. Implements abstract org. Returns the specified object to the underlying
| |
| setBlockWhenExhausted | back to summary |
|---|---|
| public void setBlockWhenExhausted(boolean blockWhenExhausted) Set whether the call should block when the pool is exhausted. | |
| setMaxIdle | back to summary |
|---|---|
| public void setMaxIdle(int maxIdle) Set the maximum number of idle objects in the pool. Default is 8.
| |
| setMaxWait | back to summary |
|---|---|
| public void setMaxWait(long maxWait) Set the maximum waiting time for fetching an object from the pool. Default is -1, waiting forever.
| |
| setMinEvictableIdleTimeMillis | back to summary |
|---|---|
| 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. | |
| setMinIdle | back to summary |
|---|---|
| public void setMinIdle(int minIdle) Set the minimum number of idle objects in the pool. Default is 0.
| |
| setTimeBetweenEvictionRunsMillis | back to summary |
|---|---|
| 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. | |
| validateObject | back to summary |
|---|---|
| public boolean validateObject(PooledObject<Object> p) Implements org. Doc from org. Ensures that the instance is safe to be returned by the pool.
| |