简体   繁体   English

JasperFillManager.fillReportToFile的内存不足问题

[英]Out of memory issue with JasperFillManager.fillReportToFile

I am facing out of memory issue while generating multiple small PDF reports (say 50000 reports , 2-3 page each, file size of 50 to 60 KB). 我在生成多个小型PDF报告(例如50000个报告,每个2-3页,文件大小为50至60 KB)时遇到内存不足的问题。 The out of memory error I get after 3000 report generated. 生成3000个报告后出现内存不足错误。

After execution of below line, I see the memory is not getting cleaned up. 在执行下面的代码行后,我看到内存没有被清理干净。

JasperFillManager.fillReportToFile(compiledPath,
        file.getPath(), null, dataSource);

I have tried the below alternate code using JRSwapFileVirtualizer, but it did not help the issue. 我已经使用JRSwapFileVirtualizer尝试了以下替代代码,但没有帮助解决该问题。

dataSource = new JRBeanArrayDataSource(myBean);
swapFile =  new JRSwapFile(outputFileLocation, 1024, 1024);
virtualizer = new JRSwapFileVirtualizer(3,swapFile, true);

parameterMap = new HashMap();
parameterMap.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);


JasperFillManager.fillReportToFile(compiledPath,
        file.getPath(), parameterMap, dataSource);

dataSource = null;
virtualizer.cleanup();

jasperPrint = (JasperPrint) JRLoader.loadObject(file);

compiledPath = null;
file = null;


pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT,
    jasperPrint);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
    finalOutputfile.toString());

pdfExporter.exportReport();

Any suggestion on how to clean up memory after each report is generated will be helpful. 任何有关在生成每个报告后如何清理内存的建议都将有所帮助。

Not sure about pojo or traditional JSP web application, but with my spring application, it used to have the same out of memory issue. 不确定pojo或传统的JSP Web应用程序,但是对于我的spring应用程序,它曾经有同样的内存不足问题。 I pull out of the trace logging and find out a lot info on rendering the template. 我退出了跟踪日志记录,并找到了很多有关渲染模板的信息。 It make me remember that jrxml is a pre-compile template instead of .jasper . 它使我记得jrxml是预编译模板,而不是.jasper So i replace all my templates then out of memory issue never happen again. 所以我替换了我所有的模板,然后内存不足的问题再也不会发生。 Please consider this as addition to @Joop Eggen's advice. 请考虑将此作为@Joop Eggen的建议的补充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM