Search code examples
tomcat7connection-pooling

Tomcat connection pool, connection timeout


I have an application running on tomcat 7.0.65, and using org.apache.tomcat.jdbc.pool.DataSource

I have connection pool setup:

PoolProperties p = new PoolProperties();
    p.setUrl("jdbc:oracle:thin:@....");
    p.setDriverClassName("oracle.jdbc.OracleDriver");
    p.setUsername("***");
    p.setPassword("***");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1 from dual");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setName("jdbc/insurancePool");
    DataSource asyncDS = new DataSource(p);

Everyday when I try to run the application I get connection timed out exception for the first couple of tries. I am not sure why this is happening. Does firewall have anything to do with this?


Solution

  • I had the same issue with MySql everyday morning. Then I found autoReconnect parameter which can be used with JDBC URL to fix this.

    For example:

    MYSQL_URL=jdbc:mysql://10.*.*.0:3306/ABC?autoReconnect=true