<分区>
如果我的 Spring Boot 应用程序在几个小时内(例如在夜间)处于非事件状态,我会收到此错误:
2015-05-19 09:16:32.666 WARN 20582 --- [http-nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01
2015-05-19 09:16:32.668 ERROR 20582 --- [http-nio-8080-exec-6] o.h.engine.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.
试图解决这个问题,我读到 MySQL 有一个名为 wait_timeout
的参数,默认设置为 8 小时(28800 秒),在这段时间之后我所有的非事件连接都是关闭,所以我的 Spring Boot 应用程序停止工作......
我的问题是:
- 我怎样才能避免这个问题?
- 我应该增加此类参数的值吗?
- 增加这种值(value)有什么缺点吗? (如果它长时间处于非事件状态,它可能始终是我的应用程序达到的值。:/)
- 是否有另一种使用 Spring Boot 的解决方案(比如轮询或类似的东西)?
编辑
这里还有其他类似/有用的问题:
- Hibernate Communications Link Failure in Hibernate Based Java Servlet application powered by MySQL
- Spring is losing connection to the DB and does not recover or reconnect
- WARN SqlExceptionHelper:143 - SQL Error: 0, SQLState: 08S01- SqlExceptionHelper:144 - Communications link failure
- SQL Error: 0, SQLState: 08S01 Communications link failure
- https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally
- Solving a "communications link failure" with JDBC and MySQL
从上面的引用资料我可以得出结论,一种解决方案是添加 C3p0 作为附加库并正确配置它以避免通信链接错误..
这是我唯一的解决方案吗?是否有与 Spring/Spring Boot 更“集成”的解决方案(即不添加外部库)?