最近由于系统和业务重构需要,需要把线上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异常的解决的更多相关文章

  1. 【异常】No ManagedConnections available within configured blocking timeout

    Caused by: org.jboss.util.NestedSQLException: No ManagedConnections available within configured bloc ...

  2. RocketMQ的invokeSync call timeout异常的解决办法

    缘起 在RocketMQ客户端的DefaultMQPushConsumer的start方法被执行时,时不时会报出invokeSync call timeout异常,如下: Caused by: jav ...

  3. pip install 报SSL异常和timeout异常

    在安装pip3 install virtualenv时报了SSL异常 如图 pip is configured with locations that require TLS/SSL, however ...

  4. 使用StackExchange.Redis客户端进行Redis访问出现的Timeout异常排查

    问题产生 这两天业务系统在redis的使用过程中,当并行客户端数量达到200+之后,产生了大量timeout异常,典型的异常信息如下: Timeout performing HVALS Parser2 ...

  5. Nginx 504 Gateway Time-out分析及解决方法

    一.场景还原php程序在执行抓取远程图片库并保存至本地服务器的时候,出现了“504 Gateway Time-out”错误提示. 问题定位:由于图片巨多,所以下载时间很长(10分钟以上),引起网关超时 ...

  6. indy9在程序关闭时出现terminate thread timeout的BUG解决办法

    indy9在程序关闭时出现terminate thread timeout的BUG解决办法 INDY9线程有BUG,在退出程序的时候会报错:terminate thread timeout(终止线程超 ...

  7. 504 Gateway Timeout 异常

    生产销售系统出现 504 Gateway Timeout 异常,其实就是服务器响应太慢导致nginx带来超时,先不说服务端慢的优化问题:只是单纯的解决504.到网上发现了一篇文章fix it Add ...

  8. 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 ...

  9. jquery.form.js不能解决连接超时(timeout)的解决方法

    最近在使用jquery.form.js提交包含文件的表单时,碰到了一个问题:当碰上网速较慢时,而我们又设置了timeout时,例如: var options = { timeout: 3000 //限 ...

随机推荐

  1. java未来发展方向!新手入门了解

    随社会信息的发展着,java广泛应用于PC.数据中心.游戏控制台.科学超级计算机.移动电话和互联网等行业.从目前的招聘量上看,对java开发人才需求量是很大的,而且未来的仍然是主流,就业前景很好.只要 ...

  2. SAPUI5使用了哪些开源技术

    我们知道SAP UI5已经开源了,共享给了Apache开源组织后的名字叫Open UI5,虽然从API的长度上看,Open UI5比SAP UI5要短,但是两者的核心并没有多大区别,SAP UI5多了 ...

  3. 【剑指offer】包含min函数的栈,C++实现

    博客文章索引地址 博客文章中代码的github地址 1.题目 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数.在该栈中调用push.pop.top.min的时间复杂度都是o(1) ...

  4. del语句的总结

    删除属性 del 语句 可以删除对象(实例)的属性 语法: del 对象.实例变量名 del 语句 del 变量名 删除变量 del name del 列表[整数表达式] 删除列表中的元素 del L ...

  5. (function($){...})(jQuery)与$(function(){...})区别

    $(function(){...}) 这种写法和jQuery(function(){...}),$(document).ready(function(){...})作用一样,表示文档载入后需要运行的代 ...

  6. BZOJ2595 Wc2008 游览计划 【斯坦纳树】【状压DP】*

    BZOJ2595 Wc2008 游览计划 Description Input 第一行有两个整数,N和 M,描述方块的数目. 接下来 N行, 每行有 M 个非负整数, 如果该整数为 0, 则该方块为一个 ...

  7. HTTP Client Performance Improvements

    HTTP Client Performance Improvements https://blogs.msdn.microsoft.com/webdev/2018/10/17/asp-net-core ...

  8. 《DSP using MATLAB》示例Example7.14

    代码: M = 20; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; Hrs = [1, 1, 1, zeros(1, 15), 1, 1]; % Idea ...

  9. cmd连接mysql操作命令

    连接:mysql -h主机地址 -u用户名 -p用户密码 (注:u与root可以不用加空格,其它也一样)断开:exit (回车) 创建授权:grant select on 数据库.* to 用户名@登 ...

  10. hadoop 之Hadoop生态系统

    1.Hadoop生态系统概况 Hadoop是一个能够对大量数据进行分布式处理的软件框架.具有可靠.高效.可伸缩的特点. Hadoop的核心是HDFS和Mapreduce,hadoop2.0还包括YAR ...