No ManagedConnections available within configured blocking timeout
最近某系统在发送短信到一定量的时候就会导致连接数吃紧,报如下错误:
2015-08-11 17:04:44,193 INFO [STDOUT] 解析文档时错: 应用系统编码:WF在短信平台系统中并不存在
2015-08-11 17:04:44,191 ERROR [STDERR] java.lang.NullPointerException
2015-08-11 17:04:42,672 ERROR [STDERR] org.jboss.util.NestedSQLException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ); - nested throwable: (javax.resource.ResourceException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] ))
2015-08-11 17:04:42,674 INFO [STDOUT] 出错信息:java.lang.NullPointerException
从错误日志来看,是连接超时(30000ms),且基本都是在服务启动的初期没问题,时间一长就会复现,基本可以确定是程序代码中未及时关闭某些connection导致的,正常的逻辑代码应该像下边的写法:prepareStatement和executeQuery都要关闭,connecttion更要及时关闭。
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);
}
}
}
- 上一篇: 有效的工作时间管理
- 下一篇: 写在开心保三周年之际
评论