java 连接池_Java连接池最佳实践?

在厌倦了c3p0的常量锁定后,我转向BoneCP为我的数据库替代连接池.我有一个服务器应用程序,每分钟处理大约7,000个项目,需要将这些项目记录到我们的

MySQL数据库中.我目前有100个工作线程,并设置了我的池:

BoneCPConfig config = new BoneCPConfig();

config.setJdbcUrl("jdbc:mysql://"+Settings.MYSQL_HOSTNAME+"/"+Settings.MYSQL_DATABASE+"?autoReconnectForPools=true" );

config.setUsername(Settings.MYSQL_USERNAME);

config.setPassword(Settings.MYSQL_PASSWORD);

config.setMinConnectionsPerPartition(5);

config.setMaxConnectionsPerPartition(10);

config.setPartitionCount(5);

config.setAcquireIncrement(5);

connectionPool = new BoneCP(config); // setup the connection pool

这些应用程序是否可以接受这些设置?我问,因为一两分钟后,我正在尝试在池上调用getConnection时获得BoneCP异常.谢谢您的帮助.

这是我在工作线程中用于数据库调用的代码,它不能在dbConn = this.dbPool.getConnection()行上失败.我没有正确关闭连接吗?

private void insertIntoDb() {

try {

Connection dbConn = this.dbPool.getConnection();

try {

PreparedStatement ps3 = dbConn.prepareStatement("INSERT IGNORE INTO test_table1 SET test1=?, test2=?, test3=?");

ps3.setString(1, "some string");

ps3.setString(2, "some other string");

ps3.setString(3, "more strings");

ps3.execute();

ps3.close();

PreparedStatement ps4 = dbConn.prepareStatement("INSERT IGNORE INTO test_table2 SET test1=?, test2=?, test3=?");

ps4.setString(1, "some string");

ps4.setString(2, "some other string");

ps4.setString(3, "more strings");

ps4.execute();

ps4.close();

} catch(SQLException e) {

logger.error(e.getMessage());

} finally {

try {

dbConn.close();

} catch (SQLException e) {

logger.error(e.getMessage());

}

}

} catch(SQLException e) {

logger.error(e.getMessage());

}

}

这是我看到的错误:

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

[java] WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

ERROR pool-2-thread-39 2010-09-04 13:36:19,798 com.test.testpackage.MyTask - null

java.sql.SQLException

at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:381)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值