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.exceptions.jdbc4.CommunicationsException: 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;
}
會導致沒有遍歷完池的所有連接,會遺留有超時連接在里面。
總結
以上是生活随笔為你收集整理的ci mysql空闲连接回收_数据库连接空闲回收问题 CommunicationsException: Communications link failure...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里云服务器邮件发送
- 下一篇: 【排序函数讲解】sort-C++