An exception occurred "The last packet sent successfully to the server was 0 milliseconds ago." Most of the reason is because the database recycles the connection, and the system's buffer pool is not known, and continues to use the recovered connection.
Take MySQL for example:
The first solution is to get MySQL to reclaim idle connections longer, MySQL default recycle time is 8 hours, you can add the following configuration in the MySQL directory My.ini, change the time to 1 days.
The unit is seconds, the maximum seems to be 24 days:
[Mysqld]
wait_timeout=86400
The second solution, can be configured to let the buffer pool to test whether the connection is recycled, if it is recycled, then do not continue to use, in DBCP as an example:
#SQL查询 To verify connections taken from the connection pool Dbcp.validationquery=select 1 # Indicates whether the connection is checked by the Idle connection collector (if any), and if the detection fails, the connection is removed from the pool Dbcp.testwhileidle=true #在空闲连接回收器线程运行期间休眠的时间值, measured in milliseconds, Generally smaller than Minevictableidletimemillis dbcp.timebetweenevictionrunsmillis=300000 #在每次空闲连接回收器线程 ( If there is a run-time check of the number of connections, preferably with maxactive consistent dbcp.numtestsperevictionrun=50 #连接池中连接, the time period that has been idle, was evicted from the connection pool (1000*60*60), in milliseconds dbcp.minevictableidletimemillis=3600000
The last packet sent successfully to the server was 0 milliseconds ago