关于No ManagedConnections available within configured blocking timeout异常的解决
最近由于系统和业务重构需要,需要把线上1亿数据迁移到新库,由于业务变更,新表老表结构有变化,没法直接用dba dump的方式,需要自己写转换程序迁移。今天在调试的时候,碰到一个蛋疼的问题,就是一开始查询数据都正常,但是查询几条后日志就会报超时错误,具体日志如下:
No ManagedConnections available within configured blocking timeout ( 5000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 5000 [ms] ))
搜了下这个错误,各种说法比较多,但是感觉都没说到点上,找DBA看了下,DBA直接表示这个库连接数一直吃紧,从这个错误看也是连接超时,本来以为就这么着了,但是调试了几次都是一开始正常,后来报异常,就感觉肯定还是代码有问题导致连接数吃紧,后来仔细看了下代码,发现是connection没有关闭...应该说是没有关闭全。把PrepareStatement和ResultSet关闭了,但是没把最重要的Connection关闭掉...关闭了Connection就正常了。
网上几个搜的结果太过于误导人,所以就记录一下,碰到这个错误,首先是确认自己代码是否有相关connection没关闭掉,基本都是没关闭connection导致的,最后再确认数据库连接数是不是真的吃紧。
如下代码仅供参考:
try{
conn = sourceDs.getConnection();
ps = conn.prepareStatement(selectTcBizOrder);
rs = ps.executeQuery();
if(rs.next()){
result.put("auction_id", rs.getLong("auction_id"));
result.put("logistics_status", rs.getInt("logistics_status"));
result.put("attributes", rs.getString("attributes"));
return result;
}else{
return null;
}
}catch(SQLException e){
LogFactory.getTaskLog().error("[select tc_biz_order SQLException], bizOrderId="+bizOrderId, e);
return null;
}catch(Exception e){
LogFactory.getTaskLog().error("[select tc_biz_order other Exception], bizOrderId="+bizOrderId, e);
return null;
}finally{
if(rs != null){
try{
rs.close();
}catch(SQLException e){
LogFactory.getTaskLog().error("[close ResultSet SQLException], bizOrderId="+bizOrderId, e);
}
}
if(ps != null){
try {
ps.close();
} catch (SQLException e) {
LogFactory.getTaskLog().error("[close PreparedStatement SQLException], bizOrderId="+bizOrderId, e);
}
}
if(conn != null){
try{
conn.close();
}catch(SQLException e){
LogFactory.getTaskLog().error("[close Connection SQLException], bizOrderId="+bizOrderId, e);
}
}
}
关于No ManagedConnections available within configured blocking timeout异常的解决的更多相关文章
- 【异常】No ManagedConnections available within configured blocking timeout
Caused by: org.jboss.util.NestedSQLException: No ManagedConnections available within configured bloc ...
- RocketMQ的invokeSync call timeout异常的解决办法
缘起 在RocketMQ客户端的DefaultMQPushConsumer的start方法被执行时,时不时会报出invokeSync call timeout异常,如下: Caused by: jav ...
- pip install 报SSL异常和timeout异常
在安装pip3 install virtualenv时报了SSL异常 如图 pip is configured with locations that require TLS/SSL, however ...
- 使用StackExchange.Redis客户端进行Redis访问出现的Timeout异常排查
问题产生 这两天业务系统在redis的使用过程中,当并行客户端数量达到200+之后,产生了大量timeout异常,典型的异常信息如下: Timeout performing HVALS Parser2 ...
- Nginx 504 Gateway Time-out分析及解决方法
一.场景还原php程序在执行抓取远程图片库并保存至本地服务器的时候,出现了“504 Gateway Time-out”错误提示. 问题定位:由于图片巨多,所以下载时间很长(10分钟以上),引起网关超时 ...
- indy9在程序关闭时出现terminate thread timeout的BUG解决办法
indy9在程序关闭时出现terminate thread timeout的BUG解决办法 INDY9线程有BUG,在退出程序的时候会报错:terminate thread timeout(终止线程超 ...
- 504 Gateway Timeout 异常
生产销售系统出现 504 Gateway Timeout 异常,其实就是服务器响应太慢导致nginx带来超时,先不说服务端慢的优化问题:只是单纯的解决504.到网上发现了一篇文章fix it Add ...
- redis-内存异常 Redis is configured to save RDB snapshots解决
连接reids获取数据时提示 Redis is configured to save RDB snapshots, but is currently not able to persist on di ...
- jquery.form.js不能解决连接超时(timeout)的解决方法
最近在使用jquery.form.js提交包含文件的表单时,碰到了一个问题:当碰上网速较慢时,而我们又设置了timeout时,例如: var options = { timeout: 3000 //限 ...
随机推荐
- Tensorflow 运行警告提示 Your CPU supports instructions that this TensorFlow binary was not compiled to use
由于现在神经网络这个东西比较火,准确的说是深度学习这个东西比较火,我们实验室准备靠这个东西发几个CCF A类的文章,虽然我不太懂这东西,兴趣也一般都是毕竟要跟随主流的,于是今天安装起了 Tensorf ...
- 【机器学习】集成学习之sklearn中的xgboost基本用法
原创博文,转载请注明出处!本文代码的github地址 博客索引地址 1.数据集 数据集使用sklearn自带的手写数字识别数据集mnist,通过函数datasets导入.mnist共1797个样 ...
- Mysql 分组查询最高分
今天告诉我要写一个服务,目的是按照每个班中各分组中竞赛最高分组平分小组得分给各个成员的服务,于是就有两个技术需求 1 查询每个班的冠军团队 2 增加一组人的分数 从“1”中,查出每个班N个分组中的得分 ...
- HDU5126 stars【CDQ分治】*
HDU5126 stars Problem Description John loves to see the sky. A day has Q times. Each time John will ...
- 如何通过eclipse查看、阅读hadoop2.4源码
问题导读:1.官网src包下载包,能否直接使用?2.如何跟踪和查看hadoop源码? 此篇是从零教你如何获取hadoop2.4源码并使用eclipse关联hadoop2.4源码基础上的一个继续,上文其 ...
- A Corrupt Mayor's Performance Art
Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless pain ...
- REST服务开发实战【转】
原文:http://kb.cnblogs.com/page/91827/ REST介绍 如果要说什么是REST的话,那最好先从Web(万维网)说起. 什么是Web呢?读者可以查看维基百科的词条(htt ...
- Mysql-Proxy 读写分离的各种坑,特别是复制延迟时
延迟问题读写分离不能回避的问题之一就是延迟,可以考虑Google提供的SemiSyncReplicationDesign补丁. 端口问题MySQL-Proxy缺省使用的是4040端口,如果你想透明的把 ...
- win7下安装ubuntu14.04lts 双系统
首先,在win7下的硬盘管理 压缩出一块空闲的分区,即压缩卷之后,不做任何操作. 并且确保该空闲卷是“基本”类型 不是的话,参考http://www.jianshu.com/p/2f07312 ...
- 研究ecmall一些流程、结构笔记 (转)
index.phpECMall::startup() //ecmall.php object //所有类的基础类 ecmall.phpBaseApp //控制器基础类 app.base.phpECBa ...