ad-inf
ad-inf

Reputation: 1570

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). The out of memory error I get after 3000 report generated.

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.

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.

Upvotes: 2

Views: 2202

Answers (1)

Dreamer
Dreamer

Reputation: 7549

Not sure about pojo or traditional JSP web application, but with my spring application, it used to have the same out of memory issue. 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. So i replace all my templates then out of memory issue never happen again. Please consider this as addition to @Joop Eggen's advice.

Upvotes: 1

Related Questions