我有一个巨大的 .xml
作为数据源(大约 100 MB)。如何在没有 java.lang.OutOfMemoryError: Java heap space
的情况下高效地使用此 xml 准备 pdf?
HashMap<String, Object> params = new HashMap<String,Object>();
// below i get: java.lang.OutOfMemoryError
Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(dataSource));
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
jasperPrint = JasperFillManager.fillReport(jasperReport, params);
最佳答案
如果可能的话,您可以增加堆。但是为一个 100MB 的 xml 文件创建一个 DOM 加上在同一个 JVM 中创建一个 pdf 文档确实需要大量内存。尝试使用基于事件的 SAX 解析器处理输入文件。这应该会显着减少内存占用!
关于java - Jasper Reports 和巨大的 XML 作为数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9679652/