Vicky
Vicky

Reputation: 1542

C3p0 connection pool size increasing randomly for each call

I am working on middleware technology Hibernate in that for increasing connection efficiency i used c3po and i have configured the following parameters but while during each call ti the service the connection pool size increasing randomly without control and each time its increasing connection without using previous connection which is opened and remaining idle below i have proivided the configuration parameters , kindly tell me what i miss to configure

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
        <property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.max_size">100</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.maxIdleTime">3600</property>
        <property name="hibernate.c3p0.maxIdleTimeExcessConnections">300</property>
        <property name="hibernate.c3p0.acquire_increment">4</property>
        <property name="hibernate.c3p0.idle_test_period">30</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
        <property name="hibernate.c3p0.testConnectionOnCheckin">true</property> 
        <property name="hibernate.c3p0.testConnectionOnCheckout">false</property>'

Upvotes: 0

Views: 393

Answers (1)

OldCurmudgeon
OldCurmudgeon

Reputation: 65821

One common mistake using connection pooling is forgetting to close the connection once you have finished with it. Generally, a connection pool system such as C3PO wraps the real connection in a proxy and redirects the close method to perform a release to the pool.

Without more details of your code it is difficult to say what your problem is but this is certainly a common mistake - I made it too the first time I used a connection pool.

In brief - remember to close your connections when you've finished with it.

The pattern you should be using should be something like:

Connection connection;
try {
  connection = getConnection();
  ...
} finally {
  if ( connection != null ) {
    connection.close();
  }
}

Upvotes: 3

Related Questions