首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Java Connection Pooling绝佳练习

2012-08-16 
Java Connection Pooling最佳练习After getting fed up with c3p0s constant locking Im turning to bon

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.

热点排行