读书人

Java Connection Pooling绝佳练习

发布时间: 2012-08-16 12:02:16 作者: rapoo

Java Connection Pooling最佳练习

After getting fed up with c3p0's constant locking I'm turning to boneCP for an alternative Connection Pool for my Database. I have a server app that processes around 7,000 items per minute and needs to log those items into our mysql database. I currently have 100 worker threads and have set up my Pool like such:

?

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.

here is the code I was using for the db calls in my worker threads, it can't failing on the?dbConn = this.dbPool.getConnection()?line. Am I not closing connections properly?

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) {}}
?

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

读书人网 >其他数据库

热点推荐