簡體   English   中英

ORA-12518,TNS:偵聽器無法移交客戶端連接來自存在大量內存訪問的循環

[英]ORA-12518, TNS:listener could not hand off client connection comes from a loop with heavy memory access

我有一個循環,可以從oracle訪問大量內存。

    int firstResult = 0;
    int maxResult = 500;
    int targetTotal = 8000; // more or less

    int phase = 1;
    for (int i = 0; i<= targetTotal; i += maxResult) {
        try {
            Session session = .... init hibernate session ...
            // Start Transaction
            List<Accounts> importableInvAcList = ...getting list using session and firstResult-maxResult...

            List<ContractData> dataList = new ArrayList<>();
            List<ErrorData> errorDataList = new ArrayList<>();

            for (Accounts account : importableInvAcList) {
                ... Converting 500 Accounts object to ContractData object ...
                ... along with 5 more database call using existing session ...
                .. On converting The object we generate thousands of ErrorData...

                dataList.add(.. converted account to Contract data ..);
                errorDataList.add(.. generated error data ..);
            }

            dataList.stream().forEach(session::save); // 500 data

            errorDataList.stream().forEach(session::save); // 10,000-5,000 data

            ... Commit Transaction ...
            phase++;
        } catch (Exception e) {

            return;
        }
    }

在第二階段(第二循環),出現異常。 有時在第三或第五階段會出現異常。

我還檢查了運行時內存。

    Runtime runtime = Runtime.getRuntime();
    long total = runtime.totalMemory();
    long free = runtime.freeMemory();
    long used = total - free;
    long max = runtime.maxMemory();

在第二階段,樣品的狀態在下面...

已使用: 1022 MB ,可用: 313 MB ,已分配的總容量: 1335 MB

堆棧跟蹤在這里...

    org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1463)
        at ibbl.remote.tx.TxSessionImpl.beginTx(TxSessionImpl.java:41)
        at ibbl.remote.tx.TxController.initPersistence(TxController.java:70)
        at com.ibbl.data.util.CDExporter2.run(CDExporter2.java:130)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12518, TNS:listener could not hand off client connection

注意,此進程在Thread中運行,並且一次有3個類似的Thread在運行。 為什么此異常在循環運行一段時間后仍然掛出?

一次有3個類似的線程在運行。

如果您的代碼創建了總共3個線程,那么最佳狀態下,您僅需要3個Oracle Connections。 在創建任何線程之前,先創建所有這些線程。 創建線程,為每個線程分配一個連接,然后啟動線程。

不過,很有可能您的代碼可能會過於激進地占用托管它的任何計算機上的資源。 即使您取消了ORA-12518,RDBMS服務器也可能“向南”。 “往南走”的意思是,如果您的應用程序占用了太多資源,則托管它的計算機或托管RDBMS服務器的計算機可能會“慌張”或同樣令人恐懼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM