简体   繁体   English

Java + Oracle ORA-1000超过最大打开游标

[英]Java + Oracle ORA-1000 Maximum open cursors exceeded

I have a multithreaded application where the main thread creates a few threads and hands them off to the ExecutorService. 我有一个多线程应用程序,其中主线程创建了几个线程并将其交给ExecutorService。 All the threads use a Oracle Database connection object in the main class. 所有线程在主类中使用Oracle数据库连接对象。 The database connection is opened once and all the methods in the other threads use the main database object. 数据库连接一次打开,其他线程中的所有方法都使用主数据库对象。

However once the application starts running and processing the records, I see that the number of cursors open keeps increasing until 2000 ( I set this limit in Oracle ) and then results in the ORA-1000 message which do not go away until I restart the application. 但是,一旦应用程序开始运行并处理记录,我看到打开的游标数量一直增加到2000年(我在Oracle中设置了此限制),然后导致ORA-1000消息直到我重新启动应用程序后才消失。 I am closing the resultsets on all the methods as well as the statements and am unable to figure out why the cursor count doesnt decrease ( Even when I run a single thread ) 我正在关闭所有方法以及语句的结果集,并且无法弄清为什么游标数量没有减少(即使当我运行单个线程时)

Here is one method: 这是一种方法:

private boolean GetPending()
{
    try {
        String statement = "SELECT * FROM PENDING_REQUESTS WHERE REQUEST_ID = GET_PENDING()";
        PreparedStatement query = DbConnection.prepareStatement(statement);
        ResultSet rs = query.executeQuery();
        while (rs.next()) {
            MSISDN = rs.getInt(3);
            SHORTCODE = rs.getInt(4);
            MESSAGE = rs.getString(5);
            return true;
        }
        rs.close();
        query.close();
    }
    catch(SQLException e) {
        LogWriter.Log("ID:"+ID+"\t\tError returning field: " + e.toString());
    }
    return false;   
}

I have also noticed that if I release the connection when the error occurs, the cursors are released. 我还注意到,如果在发生错误时释放连接,则会释放游标。 However I do not want to create a new connection for each new request since it will slow down the entire application. 但是,我不想为每个新请求创建一个新连接,因为它会减慢整个应用程序的速度。

Any help is appreciated. 任何帮助表示赞赏。 Thanks 谢谢

Few problems there: 那里的几个问题:

You are not closing your connections. 您没有关闭连接。 Close your connections on the finally . finally关闭您的连接。

You are not closing rs or query (+1 immibis) 您没有关闭rs或查询(+1 immibis)

Have you thought of using a Spring jdbc template? 您是否考虑过使用Spring jdbc模板? Also check on connection pools. 还要检查连接池。 They are your friend. 他们是你的朋友。

You need to close resultSet and prepared statement. 您需要关闭resultSet和prepared语句。 In your code it is not done. 在您的代码中未完成。 The best way is to do this in final block so even if exception happens resultSet are properly closed or if you use java7 use try-with-resources 最好的方法是在最终块中执行此操作,因此即使发生异常,resultSet也已正确关闭,或者如果您使用java7,请使用try-with-resources

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java jdbc和oracle - 超出了最大打开游标数 - java jdbc and oracle - maximum open cursors exceeded Java和oracle中最大打开游标超出异常 - maximum open cursors exceeded exception in java and oracle ORA-01000:超出最大打开游标 - java代码失败 - ORA-01000: maximum open cursors exceeded - java code fails 带有Oracle数组的Spring StoredProcedure:ORA-01000:超过了最大打开游标 - Spring StoredProcedure with Oracle array : ORA-01000: maximum open cursors exceeded 获取java.sql.SQLException:-ORA-01000:DML(更新语句)超出了最大打开游标 - Getting java.sql.SQLException: - ORA-01000: maximum open cursors exceeded for DML (Update Statement) java.sql.SQLException:ORA-01000:截断表时超出了最大打开游标 - java.sql.SQLException: ORA-01000: maximum open cursors exceeded while truncating tables Java代码中的最大打开游标超出异常 - maximum open cursors exceeded exception in java code 无法解决错误-java.sql.SQLException:ORA-01000:超出了最大打开游标 - Unable to resolve error - java.sql.SQLException: ORA-01000: maximum open cursors exceeded java.sql.SQLException:ORA-01000:超出了最大打开游标 - java.sql.SQLException: ORA-01000: maximum open cursors exceeded java.sql.SQLException: - ORA-01000: 超出最大打开游标数 - java.sql.SQLException: - ORA-01000: maximum open cursors exceeded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM