dbcp mysql关闭连接池_使用Hibernate和Apache DBCP的MySQL连接池问题

似乎与我的应用程序有关。每当启动应用程序很长时间(不确定确切的时间)后,我的日志中都会出现以下错误消息。我正在使用Spring + Hibernate +

MySQL和ApacheDBCP进行连接池

ERROR [org.hibernate.util.JDBCExceptionReporter]The last packet successfully received from the server was 74,188,684 milliseconds ago.

The last packet sent successfully to the server was 74,188,685 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.

org.hibernate.exception.JDBCConnectionException: could not execute query

如果我重新启动URL,则一切正常。我认为这与我的连接池有关。这是我的Apache

DBCP设置,MYSQL中的wait_timeout设置为其默认值。(28800秒或8小时)。

在搜索的同时,我发现此链接可以解决此问题。

使用autoReconnect = true配置连接字符串

这将有助于解决问题吗?在上面提到的同一问题中,另一位作者说,建议不要使用此解决方案。

增加MySQL服务器变量wait_timeout的值。

我不确定这将如何解决错误。如果有帮助,如何计算适当的wait_timeout值。我的意思是应该根据什么条件?

配置连接池以测试连接的有效性。

经过研究,我知道可以在进行实际查询之前使用validationQuery =“ SELECT 1”来检查连接性,这对解决问题有帮助吗?是否会影响性能?

问题不仅是特定于Apache DBCP的,我也在C3P0中看到过。

请帮忙。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值