1

I have a report that takes a select that return me about 900k records (it´s about 100MB of data) and I need to create a PDF with it.

So, my implementation is simple: I get the data from my JDBC Query, put into a ArrayList and pass it to my report. I had some problems with memory but I fixed it, my problem now is with CPU processing (it is always at 100%) that makes my process crash.

My code is really simple:

 public OutputStream getOutputStream(OutputStream out) {
        try {
            JasperPrint print = JasperFillManager.fillReport(jasperName, params, fillList);
            JRExporter exporter = format.getExporter();
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
            exporter.exportReport();

        } catch (Exception e) {
            throw new RuntimeException("Error getting the stream", e);
        }
        return out;
    }

I would like to know:

  • How in this case could I use my CPU´s multiple cores?
  • Is there another strategy to do that?
4

1 回答 1

2

我建议的两件事。1. 尝试从 JasperReport本身触发查询,而不是将其存储在 Arraylist 中,然后将其传递给报告。

2.使用Report Virtualizer。根据您的需要,您可以使用Swap Virtualizer或Gzip virtualizer。Jasper 声称 Gzip 虚拟器将 jasper 对象压缩到原始 jasper 对象的 1/10。

虚拟器将确保无论您的数据有多大,始终使用虚拟器生成报告。我个人使用 GZip 虚拟器打印了超过 25000 份超过 500MB 大小的报告,以确保它确实正常工作。

于 2013-05-18T10:11:43.250 回答