Today I will tell you about a problem I had during these days, I am developing an application consisting of Java for server side and client-side Flex, the application had recently some problems with memory consumption discovered after analyzing this was basically for two reasons one of them related to Hibernate and the lifting of 60000 objects in memory which in the end I finished working out with NameQuery, but still had problems when running several reports since the server's memory up immeasurably then I leave the solution I found.
First of all I recommend that they have a memory problem using jVisualVM is a program that lets you connect to the server and see the number of instances in memory and then analyze what is that crazy or what is consuming, as a first step I use the program and connect to the server (Tomcat) and started throwing reports apparently the GC (Garbage Collector) running as normal but when there were many reports at once saw that the amount JRTemplatePrintText instance grew dramatically.
After some research I found that Jasper Report in the process of fill (Get the data and populating the report template with these) lifted objects in memory, then the way to address this problem in two ways: Paging and
virtualization. Page
refers to obtaining the report in chunks, instead of collecting all information at once, but as the final data have to show them together in a single report, we introduce virtualization . Virtualization is a technique that involves serializing the data, not to saturate the memory heap.
worth noting that include virtualization involves the loss of performance.
Here's an example of how we should use the virtualization:
JasperPrint jasperprint = null;
JRFileVirtualizer VIRTUALIZER = new JRFileVirtualizer (10, "tmp");
long start = System.currentTimeMillis ();
FilterParameters
. put (JRParameter.REPORT_VIRTUALIZER, virtualized)
jasperprint = JasperFillManager.fillReport (this.reportFile, this.filterParameters, this.databaseConnection)
virtualizer.setReadOnly (true);
logger.info ("Filling time:" + (System.currentTimeMillis () - start));
/ / We use the exporters to generate the report on what we want.
virtualizer.cleanup ();
the example we see is basically create a JasperPrint as you normally would but at the time of generating this JasperPrint by the method of the class fillReport JasperFillManager notice that we pass the parameters Virtualizer this basically means that Jasper anger creating temporary files in the folder that you pass as second parameter and the first parameter is used to determine the maximum file size, as a last line we must not forget to do a cleanup of the virtualized to delete the files created.
Well I hope this will serve as a simple post helped me to me to find this technique to avoid wasting memory for the generation of reports either medium or large
Vale remind them to take into account the balance between memory performance and expenditure this will can handle the maximum file size.
Greetings, Luis
0 comments:
Post a Comment