如何让CommonsPoolTargetSource池大小按需增长?

时间:2013-03-19 08:55:54

标签: java spring spring-3 spring-aop pool

我注意到当有很多请求并且达到最大池大小时,其他请求会等到资源空闲。如何设置CommonsPoolTargetSource,使其达到最大池大小时,将创建新的对象实例?多余的资源也必须在使用后释放。

最初,我尝试寻找minSize属性,但发现CommonsPoolTargetSource没有minSize属性。下面是我的web.xml的主体:

<bean id="simpleBeanTarget" class="com.bean.SimpleBean" scope="prototype">        
</bean>

<bean id="poolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
    <property name="targetBeanName" value="simpleBeanTarget" />
    <property name="maxSize" value="3" />
    <!-- How do I let the pool grow if more than 3 instances is needed? -->
    <!-- And how do I release the excess instances after usage? -->
</bean>

<bean id="simpleBean" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="targetSource" ref="poolTargetSource" />
</bean>

1 个答案:

答案 0 :(得分:2)

尝试<property name="whenExhaustedActionName" value="WHEN_EXHAUSTED_GROW" />

<property name="whenExhaustedAction">
 <util:constant static-field="org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_GROW"/>
</property>