0

I'm building an app in a tomcat server (JSP+Servlet+Hibernate(MYSQL)), but when I test this app, when have passed 24 hrs, I recieve this error.

The last packet successfully received from the server was 59,480,937 milliseconds ago. The last packet sent successfully to the server was 59,480,937 milliseconds ago. is longer than the server configured value of 'wait_timeout'.

How can I solve it?

Should add I wait_timeout on hibernate conf file? Should change I something on my DB?

Thanks :)

Abraham
  • 189
  • 1
  • 18
  • Is this relevant to your problem? https://stackoverflow.com/questions/4209454/a-persistent-connection-with-jdbc-to-mysql – O. Jones Jul 29 '18 at 11:24
  • I tried to do a conecction pool, but I couldn't. What I wan is that when somebody comes to the app dont recieve this error message. Dont exist an easiest way? For example a way to "reboot" the conection in for example 24hrs? I have no idea about that, so maybe the things that I'm saying are imposible. – Abraham Jul 29 '18 at 14:02

1 Answers1

1

The connection between your servlet and the MySQL server is timing out because it doesn't get used often enough.

If your servlet has a high workload (if it serves many web users) the best way to solve this problem is to make connection pools work. That is a little complex but it is worth the trouble for many reasons, including performance. It certainly is the most common way to use JDBC connections from servlets. Connection pooling hides these issues of timeout.

If your workload is low, you can solve this problem by opening the MySQL connection each time you need it and closing it when you're done using it.

Or, you could set up an exception handler to close and reopen the connection when you get an error like this.

Or you could set up some kind of time-based service to use your connection to do a simple MySQL operation.

This may also help. Java+Tomcat, Dying database connection?

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • My workload is low for now... In the future ,I dont know if this will have high worload.And about de conection ,I open session all the times that I need to connect with the DB. What do you recomend me? And acbout the connection pool. Should I change all my code? – Abraham Jul 30 '18 at 13:34