0

I am getting following error.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 37,787,544 milliseconds ago. The last packet sent successfully to the server was 37,787,544 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.

Once I restart the application, it works OK for some time and then the same error comes up.

5
  • 1
    I assume your question is "how do I fix this?". Did you try the suggestions in the error message? Are you using pooling? Have you checked for hung connections? Commented Aug 5, 2011 at 5:59
  • Um, that timeout setting is over 10 hours. How long is "some time"? Commented Aug 5, 2011 at 6:00
  • @bdares, where do you see what "wait_timeout" is set to? Commented Aug 5, 2011 at 6:04
  • @bdares I guess default wait_timeout is 8hrs -- 28800 secs. And it's inactive since last 10 hrs. Commented Aug 5, 2011 at 6:05
  • Er yeah. I meant that the timeout setting would have to be over 10 hours for the connection to not die after that much idle time... Commented Aug 5, 2011 at 6:55

2 Answers 2

1

There are a couple of things you can do,

  1. configure wait_timeout to a very long value a day or two. See here
  2. Appenf autoReconnect=true in your MySQL connection URL jdbc:mysql://yourhost:port/dbname?autoReconnect=true
Sign up to request clarification or add additional context in comments.

Comments

0

Your connections are expiring because you're creating them and keeping them "forever".

The best approach is to use a connection pool, such as Apache's DBCP - DataBase Connection Pool.

One of the things a pool gives you is it checks the validity of the connection before giving it to you - if the connection is "no good" (it runs a simple query to assert this), it closes it and creates a new one then give you the new one. This neatly caters for expiration.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.