0

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.

Zeus
  • 6,386
  • 6
  • 54
  • 89

2 Answers2

1

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.

Hannes
  • 2,018
  • 25
  • 32
  • Are you saying that even after I call close() on the connection, the getTotalLeased() will still show as if the connections are being used? \ – Zeus Sep 10 '14 at 18:08
  • 1
    It depends on the pool implementation but you basicaly get a wrapper of the real connection and the close method is signaling the pool of a freed connection. – Hannes Sep 10 '14 at 19:24
0

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;
Zeus
  • 6,386
  • 6
  • 54
  • 89