Java BoneCP MySQL连接超时
I have an application set up to pool mysql connections with BoneCP. Right now, the application isn't getting a ton of use, so the connections aren't used as frequently. After a certain amount of time, queries that once worked, start to fail, and I get messages similar to this:
我有一个应用程序设置为与BoneCP池连接mysql。目前,该应用程序没有大量使用,因此不经常使用连接。经过一段时间后,查询一旦工作,开始失败,我得到类似这样的消息:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 2,618,063 milliseconds ago. The last packet sent successfully to the server was 44,734 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3567)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3456)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
at com.jolbox.bonecp.PreparedStatementHandle.execute(PreparedStatementHandle.java:138)
I am setting up BoneCP like this:
我正在设置BoneCP,如下所示:
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + "/" + database);
config.setUsername(username);
config.setPassword(password);
config.setMinConnectionsPerPartition(minPoolSize);
config.setMaxConnectionsPerPartition(maxPoolSize);
config.setIdleConnectionTestPeriodInMinutes(60);
config.setIdleMaxAgeInMinutes(240);
config.setPartitionCount(1);
connectionPool = new BoneCP(config);
I'm unsure of how to find out what the timeout is for the mysql server (it hasn't been changed from whatever the default is), but I get this error after around 5 or 10 mins of no connection pool activity, which seems extremely short.
我不确定如何找出mysql服务器的超时(它没有从默认设置中更改),但是在没有连接池活动大约5或10分钟后我收到此错误,这似乎非常短。
1 个解决方案
#1
5
Either you'll have to configure mysqls idle timeout (setting wait_timeout = X / interactive_timeout = X), or you could configure the connection pool to issue keep-alive statements:
您必须配置mysqls idle timeout(设置wait_timeout = X / interactive_timeout = X),或者您可以配置连接池以发出keep-alive语句:
config.setIdleConnectionTestPeriodInMinutes(10);
config.setConnectionTestStatement("/* ping */ SELECT 1"):
更多相关文章
- MySql 优化之like语句
- c语言把mysql数据库语句和变量封装为一个语句
- sql语句之union与join的区别
- MySQL中一些查看事务和锁情况的常用语句
- Android应用程序与外部数据库之间的安全性
- mysql sql语句实现隐藏手机号码中间四位
- 有没有什么MYSQL语句可以判断表是否存在并且创建?
- 制作一个基本的angularjs应用程序对我不起作用,我也不知道为什么
- 【JavaScript】JavaScript的对象-对象专门语句