Class AbstractPoolingTargetSource

  extended by
      extended by
          extended by
All Implemented Interfaces:
Serializable, PoolingConfig, TargetClassAware, TargetSource, BeanFactoryAware, DisposableBean
Direct Known Subclasses:

public abstract class AbstractPoolingTargetSource
extends AbstractPrototypeBasedTargetSource
implements PoolingConfig, DisposableBean

Abstract base class for pooling TargetSource implementations which maintain a pool of target instances, acquiring and releasing a target object from the pool for each method invocation. This abstract base class is independent of concrete pooling technology; see the subclass CommonsPoolTargetSource for a concrete example.

Subclasses must implement the getTarget() and releaseTarget(java.lang.Object) methods based on their chosen object pool. The AbstractPrototypeBasedTargetSource.newPrototypeInstance() method inherited from AbstractPrototypeBasedTargetSource can be used to create objects in order to put them into the pool.

Subclasses must also implement some of the monitoring methods from the PoolingConfig interface. The getPoolingConfigMixin() method makes these stats available on proxied objects through an IntroductionAdvisor.

This class implements the DisposableBean interface in order to force subclasses to implement a DisposableBean.destroy() method, closing down their object pool.

Rod Johnson, Juergen Hoeller
See Also:
getTarget(), releaseTarget(java.lang.Object), DisposableBean.destroy(), Serialized Form

Field Summary
Fields inherited from class
Constructor Summary
Method Summary
protected abstract  void createPool()
          Create the pool.
 int getMaxSize()
          Return the maximum size of the pool.
 DefaultIntroductionAdvisor getPoolingConfigMixin()
          Return an IntroductionAdvisor that providing a mixin exposing statistics about the pool maintained by this object.
abstract  Object getTarget()
          Acquire an object from the pool.
abstract  void releaseTarget(Object target)
          Return the given object to the pool.
 void setBeanFactory(BeanFactory beanFactory)
          Set the owning BeanFactory.
 void setMaxSize(int maxSize)
          Set the maximum size of the pool.
Methods inherited from class
destroyPrototypeInstance, newPrototypeInstance, writeReplace
Methods inherited from class
copyFrom, equals, getBeanFactory, getTargetBeanName, getTargetClass, hashCode, isStatic, setTargetBeanName, setTargetClass, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface
getActiveCount, getIdleCount
Methods inherited from interface org.springframework.beans.factory.DisposableBean

Constructor Detail


public AbstractPoolingTargetSource()
Method Detail


public void setMaxSize(int maxSize)
Set the maximum size of the pool. Default is -1, indicating no size limit.


public int getMaxSize()
Return the maximum size of the pool.

Specified by:
getMaxSize in interface PoolingConfig


public final void setBeanFactory(BeanFactory beanFactory)
                          throws BeansException
Description copied from class: AbstractBeanFactoryBasedTargetSource
Set the owning BeanFactory. We need to save a reference so that we can use the getBean method on every invocation.

Specified by:
setBeanFactory in interface BeanFactoryAware
setBeanFactory in class AbstractPrototypeBasedTargetSource
beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
BeansException - in case of initialization errors
See Also:


protected abstract void createPool()
                            throws Exception
Create the pool.

Exception - to avoid placing constraints on pooling APIs


public abstract Object getTarget()
                          throws Exception
Acquire an object from the pool.

Specified by:
getTarget in interface TargetSource
an object from the pool
Exception - we may need to deal with checked exceptions from pool APIs, so we're forgiving with our exception signature


public abstract void releaseTarget(Object target)
                            throws Exception
Return the given object to the pool.

Specified by:
releaseTarget in interface TargetSource
releaseTarget in class AbstractBeanFactoryBasedTargetSource
target - object that must have been acquired from the pool via a call to getTarget()
Exception - to allow pooling APIs to throw exception
See Also:


public DefaultIntroductionAdvisor getPoolingConfigMixin()
Return an IntroductionAdvisor that providing a mixin exposing statistics about the pool maintained by this object.