問題描述
executeBatch JDBC 的堆大小錯誤 (Heapsize error with executeBatch JDBC)
我正在使用addBatch / executeBatch在Oracle數據庫表中插入一些記錄,但是我遇到了以下heapsize錯誤
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.reflect.Array.newArray(Native Method)
at java.lang.reflect.Array.newInstance(Array.java:52)
at oracle.jdbc.driver.BufferCache.get(BufferCache.java:212)
at oracle.jdbc.driver.PhysicalConnection.getCharBuffer(PhysicalConnection.java:7422)
at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2826)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9973)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
我添加了以下參數
‑Xms1024m ‑Xmx1024m
在沒有運氣的情況下調用程序。添加 1024m 對於 180k 記錄來說很好,但它一直在 290k 崩潰。我嘗試將其增加到 4024m,但沒有幫助。
參考解法
方法 1:
For every setting of the memory parameter you will find a record number that will fail.
Divide the rows in blocks of a manageable size and issue after adding of each block
sendBatch()
In Oracle you may also set
setExecuteBatch(blockSize)
where blockSize
is the number of rows that will be passed in each roundtrip.
(by Mr. H、Marmite Bomber)