0
<beans:bean id="scimDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <beans:property name="driverClassName" value="${oracle.driver}" />
        <beans:property name="url" value="${oracle.url}" />
        <beans:property name="username" value="${oracle.user}" />
        <beans:property name="password" value="${oracle.password}" />
        <beans:property name="initialSize" value="2" />
        <beans:property name="maxActive" value="15" />
        <beans:property name="maxIdle" value="3" />
    </beans:bean>

This is the configuration im using to create pool. I want the 2 connection to be open as soon as the application starts. But now its opening the first connection after i make the first request.Then its available in the pool.

How can i open all the connection in the beginning itself?

Santosh Hegde
  • 3,420
  • 10
  • 35
  • 51
  • 1
    How do you know it just opened one instead of two? – Duncan Apr 22 '16 at 10:30
  • Based on the responses time.Its taking more time for first connection.After the first call,connection will be returned instantly.If i make another call parallel to first request its taking long time again.If 2 connections are initialised already,then parallel should be fast . – Santosh Hegde Apr 22 '16 at 11:22
  • I suggest you should check the active connections in your DB instead of the time consumed. If you use MySql, you can refer this one. http://stackoverflow.com/questions/7432241/mysql-show-status-active-or-total-connections – Duncan Apr 25 '16 at 10:25
  • Now i realised that its not opening the specified no of connection on startup.But during my first request to DB,its opening specified no of connections and caching in the pool. – Santosh Hegde Apr 25 '16 at 11:37

1 Answers1

2

https://commons.apache.org/proper/commons-dbcp/configuration.html

paramenter initialSize - The initial number of connections that are created when the pool is started.

zond
  • 1,473
  • 1
  • 21
  • 34
  • But its not opening in the beginning. As soon as i make the first call, its opening. Anything else should i add in the code or parameters required? – Santosh Hegde Apr 22 '16 at 10:32
  • Well, what about testOnCreate parameter? I see, that Santosh has the initialSize parameter in place and still don't work, I assume? Wouldn't testOnCreate actually open the connection, regardless reason why is he doing it? Or run validationQuery? – holmicz Apr 22 '16 at 10:33
  • Maybe it's not the problem of the pool but of spring not loading the bean. [Stack Overflow question](http://stackoverflow.com/questions/6684451/executing-a-java-class-at-application-startup-using-spring-mvc) – Patrick Apr 22 '16 at 10:35
  • Santosh Hegde , it depends on your app logic. You can use some method to initiate da connection in your app (on startup). Most of apps are using db on starting to initiate some data. – zond Apr 22 '16 at 11:04
  • Zond,as per the documentation it should open 2 connections. But it's not happening.is there any way to initialize minimum no of connections – Santosh Hegde Apr 22 '16 at 11:55