Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-215

DBCP's initialSize doesn't work as expected



    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.3
    • Labels:
    • Environment:

      Windows XP, jsdk1.4.2_07, Tomcat 5.0.28, commons-dbcp-1.2.2, commons-pool-1.3, hibernate 2.1.7c, mysql-connector-java-5.0.5, MySQL 5.1.11


      I've configured a datasource on Tomcat 5.0.28 using DBCP.
      Reading it's documentation i found out a parameter to specify the datasource's initial number of connections, the "initialSize" parameter. We want this configured so the first users of our system don't have to wait for the datasource to open the first connections to the database.

      When put it to work, it didn't initialize the connections as defined on the "initialSize" parameter.
      I've made a lot of tests using the "minIdle" parameter as well, but the connections are created only when the first user hits the application.

      The BasicDataSourceFactory class initializes the datasources parameters and the BasicDataSource class just create the initial connections when called according to the DataSource interface (most likely on the getConnection() method). IMHO, this way the initialSize parameter doesn't work as expected.

      The DBCP-147 issue changed the BasicDataSource class to include the loop that create the initial connections, but the patch don't really create the connections when the datasource is created, only when it is called.

      My suggestion is: before the BasicDataSourceFactory.createDataSource() method returns it should ask the datasource to connect to create the initial connections according to the initialSize parameter.

      #1 One way could be to make the BasicDataSource.createDataSource() method public and, if the initialSize parameter is higher than zero, call it at the end of the BasicDataSourceFactory.createDataSource() method.

      #2 Another possibility could be to create a initialize() method on BasicDataSource. According to its parameters it could create the initial connections to the database.

      #3 To avoid changes to BasicDataSource, one could create a subclass of BasicDataSource (lets call it X) with a constructor that receives an instance of the superclass. On this constructor X'd copy all the attributes from the superclass to it and call the inherited createDataSource() method. At the end of the BasicDataSourceFactory.createDataSource() method, if the initialSize parameter is higher than zero the factory would return a new instance of X passing as parameter the BasicDataSource instance that was initialized with the datasource's parameters.

      I've created as a bug since the "initialSize" parameter doesn't work as expected.

      What do you guys think of this issue?

      Thanks in advance for your time!




            • Assignee:
              leite Rafael Leite
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: