java JDBC Pool 被挂起,无法为应用程序分配资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39786297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:38:00  来源:igfitidea点击:

JDBC Pool is suspended, , cannot allocate resources to applications

javamultithreadingjdbcweblogicdatasource

提问by Trung Tr?nh

I deployed some apps in weblogic server. Few days ago, I traced logs and saw the error message:

我在 weblogic 服务器中部署了一些应用程序。前几天跟踪日志,看到报错信息:

2016-09-22 12:58:33,442 ERROR CommonService  - ------- ERROR --------- java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceDisabledException: Pool jdbc/*** is Suspended, cannot allocate resources to applications..
        at weblogic.common.resourcepool.ResourcePoolImpl.reserveResourceInternal(ResourcePoolImpl.java:377)
        at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:342)
        at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:329)
        at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:417)
        at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:324)
        at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:94)
        at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:63)
        at weblogic.jdbc.jta.DataSource.getXAConnectionFromPool(DataSource.java:1677)
        at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1475)
        at weblogic.jdbc.jta.DataSource.getConnection(DataSource.java:446)
        at weblogic.jdbc.jta.DataSource.connect(DataSource.java:403)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:364)
        at [my-package].ConnectionHandler.newDatabaseConnection(ConnectionHandler.java:37)

I think that having a app leeks connections and doesn't return them to the pool

我认为有一个应用程序韭菜连接并且不会将它们返回到池中

At temporary solution, I have to extended the the connection pool. I try to research which apps made this problem and see that some strange codes below:

在临时解决方案中,我必须扩展连接池。我尝试研究哪些应用程序导致了这个问题,并在下面看到了一些奇怪的代码:

public class ConnectionHandler
{
  ..
  public ConnectionHandler()
  {
    logger.trace("ConnectionHandler() constructor called");
  }

  static Connection newDatabaseConnection() throws SQLException
  {
    Connection conn;
    try {
      Context initContext = new InitialContext();
      DataSource dataSource = (DataSource) initContext.lookup(LOOKUP_URL);
      conn = dataSource.getConnection();
      conn.setAutoCommit(false);
    } catch (NamingException e) {
      logger.error("------- ERROR ---------", e);
      throw new ProcessingError("Could not obtain database connection!");
    }
    return conn;
  }
}

This app (SOAP service) will using the code below to query data once having requests:

一旦有请求,这个应用程序(SOAP 服务)将使用下面的代码来查询数据:

if (connectionHandler == null) {
      connectionHandler = new ConnectionHandler();
    }

    try {
      conn = connectionHandler.newDatabaseConnection();

      // Some callable statements here    

      conn.commit();

      logger.info("------- OK ---------");

    } catch (SQLException e) {
      logger.error("------- ERROR ---------", e);
    } catch (InstantiationException e) {
      logger.error("------- ERROR ---------", e);
    } catch (IllegalAccessException e) {
      logger.error("------- ERROR ---------", e);
    } catch (DossierServiceException e) {
      logger.error("------- ERROR ---------", e);
    } finally {
      jdbc.close(conn);
    }

My confusions which I do not understand yet:

我的困惑我还不明白:

  1. Using the static connection in multi threads is ok?

  2. Create new class (ConnectionHandler) for each request and then get static connection?

  3. Just close the connection without closing the ResultSet, Callable statements?

  1. 在多线程中使用静态连接可以吗?

  2. 为每个请求创建新类(ConnectionHandler)然后获取静态连接?

  3. 只关闭连接而不关闭 ResultSet、Callable 语句?

Could you help me explanation for these ones or having some solutions else to prevent this problem?

你能帮我解释一下这些问题,或者有其他一些解决方案来防止这个问题吗?

回答by Boris Pavlovi?

  1. The method is staticnot the result it's returning. staticmethod means that it's not necessary to have an instance of the enclosing class to call it

  2. Yes, that's a mistake, but, not such a big deal

  3. Yes, it would be better first to close the result set, statement and the connection, but this should do the job

  1. 该方法static不是它返回的结果。static方法意味着没有必要拥有封闭类的实例来调用它

  2. 是的,这是一个错误,但是,没什么大不了的

  3. 是的,最好先关闭结果集、语句和连接,但这应该可以完成工作

The problem with this code is that there's no conn.rollback()in catchblocks and there may be uncaught runtime exceptions that will not be rolled back

这段代码的问题在于没有conn.rollback()incatch块,并且可能存在无法回滚的未捕获的运行时异常