1

我有一个java程序,在正常工作几个小时后给我一个错误......这些程序曾经在我们早期的服务器上正常工作,它有windows server 2003现在我们已经升级到具有更高配置和新安装的windows server 2008 SQL Server 。是否有任何我遗漏的 db 设置,或者是否有任何我遗漏的操作系统设置?

我收到的例外是:

错误::

org.apache.commons.dbcp.SQLNestedException:无法创建 PoolableConnectionFactory,原因:网络错误

IOException:没有可用的缓冲区空间(达到最大连接数?):连接

4

3 回答 3

1

我在 Windows 上遇到过类似的问题,不得不更改注册表。这与套接字以高速率打开和关闭的事实有关,比操作系统清理它们的速度更快。

我不记得具体的注册表设置,但它增加了用户应用程序可用的数量或套接字连接。

如果我没记错的话,操作系统默认为 5000 个连接。

于 2011-01-13T16:38:18.900 回答
0

使用不同的数据库连接池包,如 c3p0。另外,检查它与您的 JDBC 驱动程序的兼容性。

于 2010-10-11T07:17:44.053 回答
0

我有一个 java 程序在正常工作几个小时后给我一个错误......

IOException:没有可用的缓冲区空间(达到最大连接数?)

JDBC 代码可能没有正确关闭获取连接的finally块中try的连接。这样,连接将保持打开状态,直到数据库强制超时并关闭它们。超时取决于使用的数据库配置。显然,以前的机器超时时间比较短,而新机器的超时时间比较长。当数据库因为您的应用程序从不关闭它们而耗尽可用连接时,您将收到类似的异常。

以下代码示例说明了用于资源处理的普通(基本)JDBC 习惯用法(注意代码流和代码注释):

public List<Entity> list() throws SQLException {
    // Declare resources.
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet resultSet = null;
    List<Entity> entities = new ArrayList<Entity>();

    try {
        // Acquire resources.
        connection = database.getConnection();
        statement = connection.prepareStatement("SELECT id, name, value FROM entity");
        resultSet = statement.executeQuery();

        // Gather data.
        while (resultSet.next()) {
            Entity entity = new Entity(); 
            entity.setId(resultSet.getLong("id"));
            entity.setName(resultSet.getString("name"));
            entity.setValue(resultSet.getInteger("value"));
            entities.add(entity);
        }
    } finally {
        // Close resources in reversed order.
        if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {}
        if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {}
        if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
    }

    // Return data.
    return entities;
}
于 2010-10-11T11:40:43.330 回答