码迷,mamicode.com
首页 > 数据库 > 详细

MySql的autoReconnect与autoReconnectForPools属性对比

时间:2020-01-18 16:40:31      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:ping   tin   out   code   lse   建立   driver   handle   res   

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个小时。

MySql的autoReconnect与autoReconnectForPools属性对比

标签:ping   tin   out   code   lse   建立   driver   handle   res   

原文地址:https://www.cnblogs.com/LoveShare/p/12209063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!