如何避免 c3p0 连接中的连接超时错误?
我已经设置了 TestConnectionOnCheckout = true
PreferredTestQuery = 选择 1
但是,不是固定的。 throw
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 通信链接失败
cpds.setMinPoolSize(3);
cpds.setMaxPoolSize(10);
cpds.setIdleConnectionTestPeriod(29);
cpds.setTestConnectionOnCheckout(true);
cpds.setPreferredTestQuery("SELECT 1");
我的 MySQL 数据库超时是 30 秒。我需要每 29 秒发送一次数据库调用,或者在连接超时时重新连接。 如何 ?
最佳答案
评论了
//cpds.setMinPoolSize(3);
//cpds.setMaxPoolSize(10);
//cpds.setIdleConnectionTestPeriod(29);
//cpds.setTestConnectionOnCheckout(true);
//cpds.setPreferredTestQuery("SELECT 1");
并添加了TestConnectionOnCheckin、TestConnectionOnCheckout和MaxConnectionAge
cpds.setTestConnectionOnCheckin(true);
cpds.setTestConnectionOnCheckout(false);
cpds.setMaxConnectionAge(28);
关于java - 如何避免 c3po 中的连接超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49579111/