반응형



apache poi(XSSFWorkbook API) 가 갖고 있는 메모리 이슈로 인해 full gc가 지속적으로 발생할 수 있다

이를 근본적으로 해결하기 위해서는 read 시에 메모리 사용 증대가 발생되지 않도록 개선된 무언가가 필요하다.

xml 처리 방식도 있고, 여러가지가 있지만 개인적으로 좋은 api를 발견  업무에 적용하여 해결하여서 공유하고자 한다.



출처는 https://github.com/monitorjbl/excel-streaming-reader


pom.xml에 아래 라이브러리 추가

(해당 라이브러리는 위의 git 에서 가져올 수 있다)

  <dependency>
    <groupId>com.monitorjbl</groupId>
    <artifactId>xlsx-streamer</artifactId>
    <version>2.1.0</version>
  </dependency>


결국엔 대량 데이터를 읽어오면서 대량의 메모리 이슈가 발생되므로

읽어오는 부분을 아래의 api를 적용하면 깔끔하게 해결되었음

(이해가 안되면.... 사용방법은 위 출처의 영문을 조금만 읽어보면 활용방법 파악이 될수 있다.)

import com.monitorjbl.xlsx.StreamingReader;

InputStream is = new FileInputStream(new File("/path/to/workbook.xlsx")); Workbook workbook = StreamingReader.builder() .rowCacheSize(100) // number of rows to keep in memory (defaults to 10) .bufferSize(4096) // buffer size to use when reading InputStream to file (defaults to 1024) .open(is); // InputStream or File for XLSX file (required)


반응형

+ Recent posts