views:

188

answers:

1

We're using virtualizers with JasperReports 3.7.0 to avoid running out of memory with some large queries. Found one helpful article on this topic, and there's a brief description of virtualizers in The Ultimate Guide to JasperReports, but that's just a start. I'm trying to figure out which virtualizer is ideal, and having chosen one, how to tune the configuration parameters. Anyone out there have some wisdom to offer on this topic?

Walter Gillett

+1  A: 

The JRFileVirtualizer is the original one, but it was mainly a proof of concept (written while I was evaluating JR; the JR developers have fixed it up, too). It creates a separate file for each virtualized page, which can lead to having lots of temporary files.

I recommend using the JRSwapFileVirtualizer because it creates just 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 make the system remove the swap file when it's done with the report, and it will use the virtualizer to hold reports with more than 50 pages.

The JRGzipVirtualizer was another p.o.c. virtualizer meant for systems without disk access. The report page objects compress pretty well, so you can still make some big reports if you have a decent heap memory size.

Fly