Sometimes, when filling a report, the report datasource may have a lot of data. In some cases, the generated report can become very large, larger than the memory allocated for the JVM, causing an OutOfMemoryException.
It is possible to set up JasperReports so that it stores segments of a report on disk in order to free up some memory. This can be accomplished by using the REPORT_VIRTUALIZER
built-in report parameter. The value for this parameter must be an instance of a class implementing net.sf.jasperreports.engine.JRVirtualizer
. JasperReports comes with an implementation of this interface, namely net.sf.jasperreports.engine.fill.JRFileVirtualizer
. This implementation is sufficient to handle the vast majority of large reports. If for some reason this implementation is not sufficient for our needs, we can always create our own implementation of net.sf.jasperreports.engine.JRVirtualizer
. The following example illustrates typical usage of JRVirtualizer
.
package...