mysql reconnect_MySql的autoReconnect与autoReconnectForPools属性对比

autoReconnect会向客户端抛出一个SQLException,但会尝试重新建立连接。

autoReconnectForPools将在每次执行SQL之前尝试ping服务器。

autoReconnect和autoReconnectForPools并没有什么关系。并且MySql官方并不推荐使用autoReconnect属性。

autoReconnect

Should the driver try to re-establish stale and/or dead connections? If enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don‘t handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, as a last option, investigate setting the MySQL server variable "wait_timeout" to a high value, rather than the default of 8 hours.

Default: false

Since version: 1.1

官方已经说明了:如果启用这个属性,则MySQL驱动程序将会对当前事务的已过期或者已被废弃的链接发出的查询请求抛出异常,并会在发起下一次请求之前尝试重新建立连接。官方已经不建议使用该属性,该值只建议在应用程序无法正确处理死链或已被回收的链接所导致的SQLException时使用。

解决该问题的最有方法就是调整MySQL的wait_timeout参数,使之大于8个小时。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值