简体   繁体   English

Java HSQLDB-批量插入:OutOfMemoryError:超出了GC开销限制

[英]Java HSQLDB - Bulk Batch Insert: OutOfMemoryError: GC overhead limit exceeded

I have 57 millions strings in an ArrayList, which I want to insert into an HSQLDB. 我在ArrayList中有5700万个字符串,我想将其插入到HSQLDB中。 But i always run out of memory and get an "java.lang.OutOfMemoryError: Java heap space" or "OutOfMemoryError: GC overhead limit exceeded" error during the process. 但是我总是在内存不足的情况下,在此过程中收到“ java.lang.OutOfMemoryError:Java堆空间”“ OutOfMemoryError:超出了GC开销限制”错误。

I tried any solution that was suggested here . 我尝试了这里建议的任何解决方案。

        DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
        String now = df.format(new Date());
        long iteration = 0;
        int i, size, totalSize;
        size = totalSize = values.size();
        PreparedStatement statement = connection.prepareStatement("INSERT INTO primes (P_VALUE, DATE_FOUND) VALUES (?, ?);");
        while (size > 0) {
            for (i = 0; i < 1000000 && i < size; i++) {
                iteration++;
                statement.setString(1, values.get(i));
                statement.setString(2, now);
                statement.addBatch();
            }
            values = values.subList(i, size);
            size = values.size();
            statement.executeBatch();
        }
        statement.closeOnCompletion();

I am pretty sure the problem is connected with the Java-Statement, because changing the for-loop condition doesn't change it. 我非常确定问题与Java语句有关,因为更改for循环条件不会更改它。

I tried 我试过了

  • smaller and greater batch sizes 批量越来越小
  • overwriting the statement after every executeBatch() 在每个executeBatch()之后覆盖语句
  • statement close after every executeBatch() 语句在每个executeBatch()之后关闭
  • commiting after every executeBatch() 在每个executeBatch()之后提交

It looks like you are using in-memory tables and the memory runs out when you insert a lot of rows. 看起来您正在使用内存表,并且当您插入很多行时内存用完了。

Try CREATE CACHED TABLE with a file-based database. 尝试使用基于文件的数据库创建CACHED TABLE。 You can then try different batch sizes. 然后,您可以尝试不同的批次大小。

You must also commit after each batch. 您还必须在每批之后提交。 All the inserted rows are kept in memory until you commit. 所有插入的行都保留在内存中,直到您提交。

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

相关问题 OutOfMemoryError:超出了GC开销限制 - OutOfMemoryError: GC overhead limit exceeded Java PreparedStatement java.lang.OutOfMemoryError:超出了GC开销限制 - Java PreparedStatement java.lang.OutOfMemoryError: GC overhead limit exceeded 詹金斯 java.lang.OutOfMemoryError:超出 GC 开销限制 - Jenkins java.lang.OutOfMemoryError: GC overhead limit exceeded java.lang.OutOfMemoryError:GC开销限制超出了android studio - java.lang.OutOfMemoryError: GC overhead limit exceeded android studio Gridgain:java.lang.OutOfMemoryError:超出了GC开销限制 - Gridgain: java.lang.OutOfMemoryError: GC overhead limit exceeded Spark失败了java.lang.OutOfMemoryError:超出了GC开销限制? - Spark fails with java.lang.OutOfMemoryError: GC overhead limit exceeded? SonarQube java.lang.OutOfMemoryError:超出了GC开销限制 - SonarQube java.lang.OutOfMemoryError: GC overhead limit exceeded 如何重现Java OutOfMemoryError - 超出了GC开销限制 - How to reproduce Java OutOfMemoryError - GC overhead limit exceeded Tomcat java.lang.OutOfMemoryError:超出了GC开销限制 - Tomcat java.lang.OutOfMemoryError: GC overhead limit exceeded java.lang.OutOfMemoryError:超出 GC 开销限制 - java.lang.OutOfMemoryError: GC overhead limit exceeded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM