I get this error if my Spring boot application is inactive for several hours (e.g. at night):
2015-05-19 09:16:32.666 WARN 20582 --- [http-nio-8080-exec-6] ohengine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01 2015-05-19 09:16:32.668 ERROR 20582 --- [http-nio-8080-exec-6] ohengine.jdbc.spi.SqlExceptionHelper : Communications link failure The last packet successfully received from the server was 29.792.613 milliseconds ago. The last packet sent successfully to the server was 6 milliseconds ago.
Trying to solve this problem, I read that MySQL has a parameter called wait_timeout set by default to 8 hours (28800 seconds), and after that all my inactive connections are closed, so my Spring Application Download stops working ...
My questions:
- How can I avoid this problem?
- Should I increase the value for such a parameter?
- Are there any disadvantages that increase this value? (It can always be the value reached by my application, if it has been inactive for so long ..: /)
- Is there another solution using Spring Boot (like polling or something like that)?
EDIT
There are other similar / useful questions here:
From the above links, I can conclude that one of the solutions is to add C3p0 as an additional library and set it up correctly to avoid a communication error.
Is this the only solution I have? Isn't there a more integrated solution with Spring / Spring Boot (i.e., without adding an external library)?
spring spring-boot mysql jdbc hibernate
Andrea
source share