600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > ci mysql空闲连接回收_数据库连接空闲回收问题 CommunicationsException: Communications link failure...

ci mysql空闲连接回收_数据库连接空闲回收问题 CommunicationsException: Communications link failure...

时间:2019-02-05 08:32:42

相关推荐

ci mysql空闲连接回收_数据库连接空闲回收问题 CommunicationsException: Communications link failure...

背景:由于数据库上的连接设定为空闲30分钟后关闭,那么客户端这边就需要在这此前回收掉,不然获取连接的时候会出问题

配置:

initialSize=1

minIdle=1

maxActive=20

maxWait=60000

timeBetweenEvictionRunsMillis=60000

minEvictableIdleTimeMillis=300000

phyTimeoutMillis=1500000

validationQuery=SELECT 'x'

testWhileIdle=true

testOnBorrow=false

testOnReturn=false

removeAbandoned=true

removeAbandonedTimeout=1800

logAbandoned=true

在应用运行过程中会出现异常:

{conn-110017, stmt-120323} execute error. SELECT 'x'

com.mysql.jdbc.municationsException: Communications link failure The last packet successfully received from the server was 2,256,880 milliseconds ago. The last packet sent successfully to the server was 928,132 milliseconds ago.

经过排查是因为超时而导致连接关闭了,然后发现DruidDataSource里面,如果配置了phyTimeoutMillis,那么基本上可以排除掉,但是由于下面这段代码:DruidDataSoufce.shrink

if (idleMillis < minEvictableIdleTimeMillis) {

break;

}

会导致没有遍历完池的所有连接,会遗留有超时连接在里面。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。