solve mysql invalid connection #713
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
use the mysql offen occur this Error. Error querying database. Cause:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet
successfully received from the server was 19,800,056 milliseconds ago.
The last packet sent successfully to the server was 19,800,056
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 configured values for client timeouts, or using the Connector/J
connection property 'autoReconnect=true' to avoid this problem.
Reason:
Use pooled datasource ,the idle connection could be invalid, when access
the msyql 'wait_timeout'. When call the close method to close this
connection, sometimes skip the 'pingConnection' method, so put a invalid
connection to idle Map.
my test:
2016-06-17 17:45:55,818 DEBUG [pool-1-thread-2] - Closing JDBC
Connection [com.mysql.jdbc.JDBC4Connection@7646d452] 1984353362
2016-06-17 17:45:55,818 DEBUG [pool-1-thread-2] -
============1984353362============= 0 0
(conn.getTimeElapsedSinceLastUse():0 poolPingConnectionsNotUsedFor:0)
2016-06-17 17:45:55,819 DEBUG [pool-1-thread-2] - Returned connection
1984353362 to pool.
solve this to ping connection before use.