How to avoid connection timeout in c3po?

How to avoid connection time out error in c3p0 connection ?

I have set TestConnectionOnCheckout = true
PreferredTestQuery = SELECT 1
But, not fixed. Throw

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure

        cpds.setMinPoolSize(3);
        cpds.setMaxPoolSize(10);
        cpds.setIdleConnectionTestPeriod(29);
        cpds.setTestConnectionOnCheckout(true);
        cpds.setPreferredTestQuery("SELECT 1");

My MySQL db timeout is 30 seconds. I need to send db call every 29 seconds or reconnect connection when connection is time out. How ?

Answer

Commented

    //cpds.setMinPoolSize(3);
    //cpds.setMaxPoolSize(10);
    //cpds.setIdleConnectionTestPeriod(29);
    //cpds.setTestConnectionOnCheckout(true);
    //cpds.setPreferredTestQuery("SELECT 1");

And added TestConnectionOnCheckin,TestConnectionOnCheckout and MaxConnectionAge

    cpds.setTestConnectionOnCheckin(true);
    cpds.setTestConnectionOnCheckout(false);
    cpds.setMaxConnectionAge(28);

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

Leave a Reply

Your email address will not be published. Required fields are marked *