0

空中楼阁之纸上谈兵 mysql的dbcp的配置

 2 years ago
source link: https://club.perfma.com/article/2374952
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
空中楼阁之纸上谈兵 mysql的dbcp的配置
文章>空中楼阁之纸上谈兵 mysql的dbcp的配置

空中楼阁之纸上谈兵 mysql的dbcp的配置

青叶竹
mysql
1天前

maxWait=-1 最大等待时间:当没有可用连接时,连接池等待连接被归还的最大时间(以毫秒计数),超过时间则抛出异常,如果设置为-1表示无限等待

testOnBorrow=true
指明是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个.
注意: 设置为true后如果要生效,validationQuery参数必须设置为非空字符串

validationQuery="",如select 1
SQL查询,用来验证从连接池取出的连接,在将连接返回给调用者之前.如果指定,则查询必须是一个SQL SELECT并且必须返回至少一行记录

validationQueryTimeout=0,如3
单位秒,validationQuery的setQueryTimeout,查询超时

testWhileIdle=false
指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除.
注意: 设置为true后如果要生效,validationQuery参数必须设置为非空字符串

timeBetweenEvictionRunsMillis=-1
在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位. 如果设置为非正数,则不运行空闲连接回收器线程

numTestsPerEvictionRun=3
在每次空闲连接回收器线程(如果有)运行时检查的连接数量

minEvictableIdleTimeMillis=1000 * 60 * 30
连接在池中保持空闲而不被空闲连接回收器线程(如果有)回收的最小时间值,单位毫秒


jdbc socket timeout配置:
jdbc:mysql://xxx.xx.xxx.xxx:3306/database?connectTimeout=60000&socketTimeout=60000


综上所述,避免dead connections,需要:
1、需要配置jdbc socket timeout
2、testOnBorrow=true 和 testWhileIdle = true


参考资料:
https://www.jianshu.com/p/6d19e0d7f81c

0人觉得很赞
958 阅读
请先登录,再评论

暂无回复,快来写下第一个回复吧~


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK