java - 如何让 CommonsPool2TargetSource 池大小根据需要增长?

标签 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>

最佳答案

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

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

关于java - 如何让 CommonsPool2TargetSource 池大小根据需要增长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15495032/

相关文章:

annotations - 我可以从 JAR 文件中注入(inject) spring bean 吗?

Java - 扩展 HashMap - 对象与泛型行为

java - Gradle , Kotlin : How to add another spring boot project as a module dependency in intellij

spring - Autowiring 到 JPA 转换器

java - spring ThreadPoolTask​​Executor 在每个方法调用上创建新线程

java - 与 gradle intellij 一起使用的环境变量 - spring boot

java - Spring 3 在所有模型属性上错误地绑定(bind)请求数据

java - KafkaEmbedded 为 SecurityProtocol 抛出 ClassNotFoundException

c# - System.convert.ToString() 与 C# 中的显式类型转换

forms - 避免 spring <form :input path ="var"/> for int variable 中的默认值