0
votes

We have BoneCP library managing our connection pools. I'd like to know if the following statement will return the connection back to the pool.

statement = conn.createStatement();
....
lots of code.
....
Connection conn = statement.getConnection();
statement.close();
conn.close();

Will the above code close the connection and put the connection back into the pool?

Update:

I'm asking this question because when I run the statistics on connectionpool, i still see the conPool.getTotalLeased() showing that 2 connections are being used. But, I've closed the connections using the above mechanism.

2

2 Answers

1
votes

The whole sense of a pool is to hold already established connections to your database. When you retrieve a connection from your pool you save the time to connect to your database.

What you are seeing is the pool holding your connections so it is all fine.

When you close your connection, it is only returned to the pool and marked as available for your next retrieval.

0
votes

Yes it does moves the connection back to the pool. There was a mistake when getting the connection from the pool, fixed it, now i'm not seeing the 2 connections in the totalLeased() method.

Mistake that I found

conPool.getConnection();  // loitering connection which we see in the getTotalLeased();
..
Statement st = conPool.getConnection().getStatement(); //we have handle to this connection.
return st;