我有两个网络服务。一个 Web 服务调用另一个 Web 服务。这些 Web 服务托管在两个不同的 AWS 实例上。如果被调用的 Web 服务空闲一段时间,我会收到此异常 -
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 49,381,933 milliseconds ago. The last packet sent successfully to the server was 49,381,933 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.
如果我重新启动 AWS 实例,就不会出现此异常。
使用Tomcat作为服务器,Mysql作为数据库,使用spring-mvc开发的webservices。
我在互联网上搜索,但发现不推荐'autoReconnect=true'。 并且不确定我可以增加多少“wait_timeout”,因为我不确定有多少时间实例将空闲。
请建议可以做什么。
最佳答案
在本例中,使用 IP 地址连接数据库时出现问题,而不是在数据库连接字符串中使用服务器的域名,问题得到解决。
关于java - 空闲 AWS 实例上的 Web 服务中出现 CommunicationsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23928030/