首页 最新文章网站编程正文

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);

  }

  }

  }

评论

觉得有用就打赏吧
关注本站公众号,享受更多服务!
联系方式
QQ:########
地址:中国·辽宁
Email:2727987445#qq.com
Copyright ©2015-2023.Powered by 云水客 | 网站地图 | 辽ICP备14000512号-5