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

Sekhar picture Sekhar · Mar 21, 2012 · Viewed 30k times · Source

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

<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.

Answer

Arnaud Gourlay picture Arnaud Gourlay · Mar 21, 2012

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

<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.html for reference.