簡體   English   中英

JasperFillManager.fillReportToFile的內存不足問題

[英]Out of memory issue with JasperFillManager.fillReportToFile

我在生成多個小型PDF報告(例如50000個報告,每個2-3頁,文件大小為50至60 KB)時遇到內存不足的問題。 生成3000個報告后出現內存不足錯誤。

在執行下面的代碼行后,我看到內存沒有被清理干凈。

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

我已經使用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();

任何有關在生成每個報告后如何清理內存的建議都將有所幫助。

不確定pojo或傳統的JSP Web應用程序,但是對於我的spring應用程序,它曾經有同樣的內存不足問題。 我退出了跟蹤日志記錄,並找到了很多有關渲染模板的信息。 它使我記得jrxml是預編譯模板,而不是.jasper 所以我替換了我所有的模板,然后內存不足的問題再也不會發生。 請考慮將此作為@Joop Eggen的建議的補充。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM