数据库连接中断-连接池druid

Posted daixianjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库连接中断-连接池druid相关的知识,希望对你有一定的参考价值。

问题:据库和应用在同一台机,数据库用mysql5.6.20,已经升级druid到最新的1.0.7版本,访问的是localhost的mysql,放一个晚上不访问,第二天访问就报错了,重启服务正常,错误提示:

[Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not inspect JDBC autocommit mode] with root cause
java.net.SocketException: Software caused connection abort: socket write error
我按照druid的示例配置了最小连接数,以及检测连接打开,但是没用的?请问怎么看druid的保持连接池最小连接的检测日志输出???我看看有没有检测连接。

解决方案:首先更改mysql的wait_timeout是不好的。

用如下配置可以解决:


<property name="validationQuery" value="select ‘x‘" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="timeBetweenEvictionRunsMillis" value="600000" />
testWhileIdle:建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于
timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
testOnBorrow:申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。

testOnReturn:归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能

 

参考:http://www.oschina.net/question/928524_165510

http://itindex.net/detail/50100-druid
---------------------
作者:jueshengtianya
来源:CSDN
原文:https://blog.csdn.net/jueshengtianya/article/details/50580945
版权声明:本文为博主原创文章,转载请附上博文链接!
















以上是关于数据库连接中断-连接池druid的主要内容,如果未能解决你的问题,请参考以下文章

Springboot集成druid数据库连接池

druid数据库连接池啥时候释放

分布式 关于 druid 连接池参数问题

有人熟悉阿里的 druid 的连接池么

数据库连接池之Druid

Alibaba-Druid 连接池使用