Java Connection Pooling best practices? Java Connection Pooling best practices? database database

Java Connection Pooling best practices?


Are those acceptable settings for such an app? I'm asking because after a minute or two into running I was getting boneCP exceptions when trying to call getConnection on the pool. thanks for the help.

If you have 100 workers, why do you limit the pool to 50 connections (number of partitions x max number of connections per partition i.e. 5 x 10 in your case)?

Am I not closing connections properly?

Looks ok (but maybe enable connectionWatch as hinted to see what the warning is about exactly). Personally, I close all the resources I use, including statement and result sets. Just in case, here is the idiom I use:

Connection conn = null;PreparedStatement pstmt = null;ResultSet rs = null;try {    conn = pool.getConnection();    pstmt = conn.prepareStatement(SOME_SQL);    pstmt.setFoo(1, foo);    ...    rs = pstmt.executeQuery();    ...} finally {    if (rs != null) try { rs.close(); } catch (SQLException quiet) {}    if (pstmt != null) try { pstmt.close(); } catch (SQLException quiet) {}    if (conn != null) try { conn.close(); } catch (SQLException quiet) {}}

You could group the above calls in a static method of a utility class.

Or you could use DbUnit.closeQuietly(Connection, Statement, ResultSet) from Commons DbUtils that already does this.