性能解析 csv 到 bean java



无法读取csv文件有超过500万行

Env: Java 8, opencsv -version 4.6, Lunix, MySQL

我的代码:

public static <T> List<T> parseCsvToBeanPosition(Class<T> clazz, Reader readerInput) {
        ColumnPositionMappingStrategy ms = new ColumnPositionMappingStrategy();
        ms.setType(clazz);
        CsvToBean<T> csvToBean =
                new CsvToBeanBuilder(readerInput)
                        .withType(clazz)
                        .withMappingStrategy(ms)
                        .build();
        return csvToBean.parse();
    }
2019-06-21 16:38:13 [http-nio-8085-exec-2] INFO SynchronizeBusiness - Start parse:  (SynchronizeBusiness.java:223)
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000abc80000, 284688384, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 284688384 bytes for committing reserved memory.
# An error report file with more information is saved as:

看起来您的应用程序消耗的内存多于分配的内存(默认(。

  1. 将 JVM 的内存分配增加到 -Xms2g -Xmx2g(如果需要,请进一步增加并尝试一下(

最新更新