【问题标题】:How to avoid connection timeout in c3po?如何避免c3po中的连接超时?
【发布时间】:2018-09-09 18:31:14
【问题描述】:

如何避免c3p0连接出现连接超时错误?

我已设置 TestConnectionOnCheckout = true
PreferredTestQuery = SELECT 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 秒发送一次数据库调用,或者在连接超时时重新连接。 如何 ?

【问题讨论】:

    标签: java mysql c3p0


    【解决方案1】:

    评论

        //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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-11
      • 2017-01-30
      • 2010-09-24
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      相关资源
      最近更新 更多