ORA-12518,TNS:侦听器无法移交来自具有大量内存访问的循环的客户端连接



我有一个循环,从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;
}
}

在第二阶段(第 2 循环(出现异常。有时例外会在第三或第五阶段出现。

我还检查了运行时内存。

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

在第二阶段,样品的状态如下...

已使用:1022MB, 免费: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 连接。在创建任何线程之前创建所有这些线程。创建线程,为每个线程分配一个连接,然后启动线程。

但是,很有可能您的代码可能会在托管它的任何计算机上过于积极地消耗资源。即使您取消了ORA-12518,RDBMS服务器也可能"向南移动"。通过"向南走",我的意思是,如果你的应用程序消耗了太多资源,托管它的机器或托管RDBMS服务器的机器可能会"恐慌"或同样可怕的事情。

最新更新