Siva
Siva

Reputation: 112

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 ?

Upvotes: 3

Views: 1330

Answers (1)

Siva
Siva

Reputation: 112

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

Upvotes: 2

Related Questions