0

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&amp;characterEncoding=utf-8&amp;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?

xiaosunzhu
  • 31
  • 7
  • I don't think [link](http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai) this have the answer. – xiaosunzhu Aug 25 '16 at 08:13
  • @M. Deinum that question maybe can not connect to MySQL. But my question is after connection idle 8 hours(wait_timeout), sometimes, may throw exception. i use dbcp pool. Not every 8 hours throw exception, and not all connections throw exception. – xiaosunzhu Aug 25 '16 at 08:17

0 Answers0