如何避免c3p0连接中的连接超时错误?
我已将TestConnectionOnCheckout设置为true
PreferredTestQuery=选择1
但是,不是固定的。投掷
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);

http://www.mchange.com/projects/c3p0/#managing_pool_size

关于java - 如何避免c3po中的连接超时?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49579111/

10-09 01:01