How to choose and configure JasperReports virtualizer?

We use virtualizers with JasperReports 3.7.0 to avoid running out of memory with some large requests. Found a useful article on this topic, as well as a brief description of virtualizers in The Ultimate Guide to JasperReports, but this is only the beginning. I am trying to figure out which virtualizer is ideal, and whether it chose how to configure the configuration settings. Does anyone have any wisdom suggested on this topic?

Walter Gillette

+3
source share
1 answer

The JRFileVirtualizer is original, but it was mostly proof of concept (written when I evaluated JR, JR developers also fixed it). It creates a separate file for each virtualized page, which can lead to a large number of temporary files.

I recommend using JRSwapFileVirtualizer because it creates only one file for the report.

JRSwapFileVirtualizer virtualizer = null;
try {
    JRSwapFile swapFile = new JRSwapFile("directory", 1024, 100);
    virtualizer = new JRSwapFileVirtualizer(50, swapFile, true);
    params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
    ...
    JasperPrinter printer = JasperFillManager.fillReport(report, params, dataSource);
    ...
}
finally {
    if (virtualizer != null) virtualizer.cleanup();
}

This will force the system to delete the page file when it is done with the report, and will use the virtualizer to store reports with more than 50 pages.

JRGzipVirtualizer was another poc virtualizer designed for diskless systems. Report page objects are compressed very well, so you can create large reports if you have a decent heap memory size.

+4
source

Source: https://habr.com/ru/post/1733453/


All Articles