DBCP连接池TestOnBorrow的坑
来源:互联网 发布:装多客软件多少钱 编辑:程序博客网 时间:2024/06/05 04:19
生产环境连接池TestOnBorrow设置为false,导致有时获取的连接不可用。分析如下:
- TestOnBorrow=false时,由于不检测池里连接的可用性,于是假如连接池中的连接被数据库关闭了,应用通过连接池getConnection时,都可能获取到这些不可用的连接,且这些连接如果不被其他线程回收的话,它们不会被连接池被废除,也不会重新被创建,占用了连接池的名额。
The last packet successfully received from the server was 19,956 milliseconds ago. The last packet sent successfully to the server was 32 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1571)Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3143) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3597) ... 8 more
- 当TestOnBorrow=true时,有两种情况:
① 集群某实例宕掉时,如果连接刚好不处于通信阶段,tcp连接正处于CLOSE_WAIT状态或已关闭,当应用通过连接池getConnection时,在borrow时会检测连接,由于连接已关闭,于是报了如下报错,并重新建立新连接,此时的新连接到集群的其他实例上了。后面能正常通信。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3143) at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:597) ... 21 more
② 集群某实例宕掉时,如果连接刚好处于通信阶段,由于客户端无法立即感知服务端已断连接,它可能会报如下错误,等待服务端的响应超时报错。当应用通过连接池getConnection时,在borrow时会检测连接,由于连接已关闭,于是报了如下报错,并重新建立新连接,此时的新连接到集群的其他实例上了。后面能正常通信。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet successfully received from the server was 10,538 milliseconds ago. The last packet sent successfully to the server was 10,306 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
0 0
- DBCP连接池TestOnBorrow的坑
- 使用druid连接池带来的坑testOnBorrow=false
- [置顶] 数据连接池默认配置带来的坑testOnBorrow=false,cloes_wait 终于解决了
- 数据连接池默认配置带来的坑testOnBorrow=false,cloes_wait 终于解决了
- 关于连接池参数testWhileIdle,testOnBorrow,testOnReturn的疑问
- DBCP 连接池的理解
- DBCP连接池的配置
- DBCP连接池的使用
- 连接池DBCP的使用
- tomcat5.5的DBCP连接池配置
- commons-dbcp连接池的分析
- 关于dbcp连接池的一个工具
- tomcat7 的dbcp连接池配置问题
- 基于Apache的DBCP建立连接池
- DBCP连接池的使用小结
- dbcp连接池实现
- DBCP连接池使用
- DBCP连接池详解
- github常见操作和常见错误!错误提示:fatal: remote origin already exists.
- OpenCV项目CMakeList实例
- HTTP中get和post的区别
- android 设置 全屏显示 以及 设置屏幕横屏显示
- SharpZipLib 文件/文件夹压缩
- DBCP连接池TestOnBorrow的坑
- 【51NOD】1183 编辑距离(最长公共子序列变形)
- easy-ui的input框联动效果js实现代码.
- leetcode:暴力枚举法之Combinations
- 微信 模版消息 (六)
- Android 关于内存泄漏的检测与优化
- Oracle:日期函数
- 详解ASP.NET配置文件Web.config
- 浅谈java中final数据