如何更快地写入apache.poi.xssf Excel工作表?

时间:2018-09-21 17:03:47

标签: java excel java-8 apache-poi

我正在使用jdbcTemplate查询ETL工具并获取结果并使用Apache POI库写入Excel工作表。我有700,000到1,000,000之间的行可以提取和写入。

之前我有以下设置:

jdbcTemplate.query(new CustomPreparedStatementCreator(arg), new ResultSetExtractor<Void>() {
    @Override
    public Void extractData(ResultSet rs) {
    while (rs.next()) {... process sequentially ...}
    // caused the connection to remain open for 650 seconds
    // setFetchSize was not set so it was default
}

现在我有以下设置:

jdbcTemplate.setFetchSize(200);
SqlRowSet srs = jdbcTemplate.queryForRowSet(sql);
// all the rows are fetched in 60 seconds into memory now
while (srs.next()) {... process sequentially ...} // still takes 600 seconds to write to the worksheet

现在我的问题是:

  1. 如何利用Java 8 parallelStream API处理SqlRowSet对象内的所有行?还有其他选择吗?
  2. 我如何才能更快地向工作表(org.apache.poi.xssf.streaming.SXSSFSheet)进行写?

0 个答案:

没有答案