如何在 Spring Framework 中为 BasicDataSource 设置最大池大小或连接大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9804892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 05:01:27  来源:igfitidea点击:

How to set the max pool size or connection size for BasicDataSource in Spring Framework

springdatabase-connectionconnection-poolingapache-commons-dbcp

提问by Sekhar

I have a Spring application deployed in JBoss EAP server, using the following settings:

我在 JBoss EAP 服务器中部署了一个 Spring 应用程序,使用以下设置:

<bean:bean id="userDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <bean:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <bean:property name="url" value="jdbc:oracle:thin:@10.8.1.5:1521:DB"/>
    <bean:property name="username" value="WEBDB"/>
    <bean:property name="password" value="WEBDB"/>
</bean:bean>

How do I configure the connection pool's min and max size?

如何配置连接池的最小和最大大小?

Any references or any best practices for BasicDataSource will be of great help.

BasicDataSource 的任何参考或任何最佳实践都会有很大帮助。

回答by Arnaud Gourlay

You could add to your userDataSource the appropriate properties, for example:

您可以向 userDataSource 添加适当的属性,例如:

<bean:property name="initialSize" value="1" />
<bean:property name="maxActive"   value="5" />
<bean:property name="maxIdle"     value="2" />

See https://commons.apache.org/proper/commons-dbcp/configuration.htmlfor reference.

请参阅https://commons.apache.org/proper/commons-dbcp/configuration.html以供参考。