druid连接泄露故障全面分析

  private Object runSql(List sqlSessionFactotyBeanNameList, MethodInvocation invocation)

  throws InvocationTargetException, IllegalAccessException {

  List sqlSessionList = Lists.newArrayList();

  Object result = null;

  try {

  for (String sessionFactotyBeanName : sqlSessionFactotyBeanNameList) {

  SqlSessionFactory sqlSessionFactory =

  RgApplicationContextUtil.getBean(

  sessionFactotyBeanName, SqlSessionFactory.class);

  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);

  Object mapper = sqlSession.getMapper(invocation.getMethod().getDeclaringClass());

  Object[] param = invocation.getArguments();

  result = invocation.getMethod().invoke(mapper, param);

  sqlSessionList.add(sqlSession);//问题代码,注意!!!!

  sqlSession.commit();

  }

  } catch (Exception ex) {

  sqlSessionList.stream()

  .forEach(

  x -> {

  x.rollback();

  });

  } finally {

  sqlSessionList.stream()

  .forEach(

  x -> {

  x.close();

  });

  }

  return result;

  }