|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource org.springframework.aop.target.AbstractPrototypeBasedTargetSource org.springframework.aop.target.AbstractPoolingTargetSource org.springframework.aop.target.CommonsPoolTargetSource
public class CommonsPoolTargetSource
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,
GenericObjectPool
,
createObjectPool()
,
AbstractPoolingTargetSource.setMaxSize(int)
,
setMaxIdle(int)
,
setMinIdle(int)
,
setMaxWait(long)
,
setTimeBetweenEvictionRunsMillis(long)
,
setMinEvictableIdleTimeMillis(long)
,
Serialized FormField Summary |
---|
Fields inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource |
---|
logger |
Constructor Summary | |
---|---|
CommonsPoolTargetSource()
Create a CommonsPoolTargetSource with default settings. |
Method Summary | |
---|---|
void |
activateObject(Object obj)
|
protected ObjectPool |
createObjectPool()
Subclasses can override this if they want to return a specific Commons pool. |
protected void |
createPool()
Creates and holds an ObjectPool instance. |
void |
destroy()
Closes the underlying ObjectPool when destroying this object. |
void |
destroyObject(Object obj)
|
int |
getActiveCount()
Return the number of active objects in the pool. |
int |
getIdleCount()
Return the number of idle objects in the pool. |
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)
|
Methods inherited from class org.springframework.aop.target.AbstractPoolingTargetSource |
---|
getMaxSize, getPoolingConfigMixin, setBeanFactory, setMaxSize |
Methods inherited from class org.springframework.aop.target.AbstractPrototypeBasedTargetSource |
---|
destroyPrototypeInstance, newPrototypeInstance |
Methods inherited from class org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource |
---|
copyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, setTargetBeanName, setTargetClass, toString, writeReplace |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CommonsPoolTargetSource()
Method Detail |
---|
public void setMaxIdle(int maxIdle)
GenericObjectPool.setMaxIdle(int)
public int getMaxIdle()
public void setMinIdle(int minIdle)
GenericObjectPool.setMinIdle(int)
public int getMinIdle()
public void setMaxWait(long maxWait)
GenericObjectPool.setMaxWait(long)
public long getMaxWait()
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
public long getTimeBetweenEvictionRunsMillis()
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Note that eviction runs need to be performed to take this setting into effect.
public long getMinEvictableIdleTimeMillis()
public void setWhenExhaustedActionName(String whenExhaustedActionName)
setWhenExhaustedAction(byte)
public void setWhenExhaustedAction(byte whenExhaustedAction)
public byte getWhenExhaustedAction()
protected final void createPool()
createPool
in class AbstractPoolingTargetSource
createObjectPool()
protected ObjectPool createObjectPool()
Default is a GenericObjectPool instance with the given pool size.
ObjectPool
.GenericObjectPool
,
AbstractPoolingTargetSource.setMaxSize(int)
public Object getTarget() throws Exception
ObjectPool
.
getTarget
in interface TargetSource
getTarget
in class AbstractPoolingTargetSource
Exception
- we may need to deal with checked exceptions from pool
APIs, so we're forgiving with our exception signaturepublic void releaseTarget(Object target) throws Exception
ObjectPool
.
releaseTarget
in interface TargetSource
releaseTarget
in class AbstractPoolingTargetSource
target
- object that must have been acquired from the pool
via a call to getTarget()
Exception
- to allow pooling APIs to throw exceptionAbstractPoolingTargetSource.getTarget()
public int getActiveCount() throws UnsupportedOperationException
PoolingConfig
getActiveCount
in interface PoolingConfig
UnsupportedOperationException
- if not supported by the poolpublic int getIdleCount() throws UnsupportedOperationException
PoolingConfig
getIdleCount
in interface PoolingConfig
UnsupportedOperationException
- if not supported by the poolpublic void destroy() throws Exception
ObjectPool
when destroying this object.
destroy
in interface DisposableBean
Exception
- in case of shutdown errors.
Exceptions will get logged but not rethrown to allow
other beans to release their resources too.public Object makeObject() throws BeansException
makeObject
in interface PoolableObjectFactory
BeansException
public void destroyObject(Object obj) throws Exception
destroyObject
in interface PoolableObjectFactory
Exception
public boolean validateObject(Object obj)
validateObject
in interface PoolableObjectFactory
public void activateObject(Object obj)
activateObject
in interface PoolableObjectFactory
public void passivateObject(Object obj)
passivateObject
in interface PoolableObjectFactory
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |