We have an API that uses Hibernate as an ORM tool, and we use c3p0 as a connection pool handler. We have no problem when we are under stress. However, we are running out of “connection failed” exceptions when the API was inactive for a day or so. Thus, if no one uses the API on weekends, we will get connection errors on Monday morning.
Reason: java.sql.SQLException: the client tried to establish a connection timed out.
We use MySQL as a database. As a result of my research, I found out that MySQL makes connections obsolete after 8 hours or so. It is possible that the connection pool issues an outdated connection with the client and, therefore, exceptions for the connection timeout for the client.
Currently we do not have any connection testing configured in C3Po. Suppose if I use IdleTestPeriod to test the connection before they are passed to the client by the pool. What happens if all my connections fail the test at a specific point in time? Will these failed connections be removed from the pool and will new active connections be generated again?
These are currently the c3p0 settings that we use. Are there other possible causes for this problem?
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${----}"/>
<property name="jdbcUrl" value="${----}"/>
<property name="user" value="${----}"/>
<property name="password" value="${------}"/>
<property name="minPoolSize" value="5"/>
<property name="acquireIncrement" value="5" />
<property name="maxPoolSize" value="125" />
<property name="maxStatements" value="10" />
<property name="maxIdleTime" value="180" />
<property name="maxIdleTimeExcessConnections" value="30" />
<property name="checkoutTimeout" value="3000" />
<property name="preferredTestQuery" value="SELECT 1" />
</bean>