I use Spring, ibatis and dbcp pool. Here is my dataSource config:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://${db.ip}:${db.port}/${db.name}?useUnicode=true&characterEncoding=utf-8&autoReconnect=true"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.pwd}"/>
<property name="initialSize" value="5"/>
<property name="maxActive" value="300"/>
<property name="maxIdle" value="50"/>
<property name="minIdle" value="3"/>
<property name="maxWait" value="120000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="180"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="false"/>
<property name="timeBetweenEvictionRunsMillis" value="100000"/>
<property name="minEvictableIdleTimeMillis" value="120000"/>
<property name="validationQuery" value="select 1"/>
<property name="numTestsPerEvictionRun" value="50"/>
</bean>
I have config testWhileIdle
,testOnBorrow
,timeBetweenEvictionRunsMillis
. But sometimes still throw CommunicationsException
:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,251,590 milliseconds ago. The last packet sent successfully to th e server was 56,251,590 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configur ed values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
Not every 8 hours throw exception, not all connection throw exception. I use wireshark to catch packages on network, indeed, each connection sent validate query(select 1) every 100000ms.
MySQL version is 5.6 and wait_timeout not modify, is 8 hours. Why still throw exception? And how to fix?