Hi,
I am experiencing OutOfMemoryErrors when generating very large reports (XLS with more than 56000 records).
There was a problem in my code, the resultset was retrieving all the database records in memory without fetching. I have corrected this problem.
But the OutOfMemoryError now occurs during the export.
I have try virtualizer after reading this http://www.jasperforge.org/index.php?option=com_content&task=view&id=250...
My code is below. I have created a virtualizer and added it the the parameters but I think it is never called (no files in my temp dir and OutOfMemoryError before an xls file is generated).
I am experiencing OutOfMemoryErrors when generating very large reports (XLS with more than 56000 records).
There was a problem in my code, the resultset was retrieving all the database records in memory without fetching. I have corrected this problem.
But the OutOfMemoryError now occurs during the export.
I have try virtualizer after reading this http://www.jasperforge.org/index.php?option=com_content&task=view&id=250...
My code is below. I have created a virtualizer and added it the the parameters but I think it is never called (no files in my temp dir and OutOfMemoryError before an xls file is generated).
Code: |
JRFileVirtualizer virtualizer = new JRFileVirtualizer( 2, Configuration.getParameter("report.virtualizer.physical.temp.path"«») );<br /> parameters.put( JRParameter.REPORT_VIRTUALIZER, virtualizer );<br /> <br /> DataSource dataSource = new DataSource( parameters, jasperReport.getQuery().getText(), connection );<br /> <br /> JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, dataSource );<br /> //-----------------------------------------------------<br /> <br /> JRXlsExporter exporterXLS = new JRXlsExporter();<br /> exporterXLS.setParameter( JRXlsExporterParameter.JASPER_PRINT, jasperPrint );<br /> //exporterXLS.setParameter( JRXlsExporterParameter.OUTPUT_STREAM, output );<br /> exporterXLS.setParameter( JRXlsExporterParameter.OUTPUT_FILE_NAME, PDFReportCreator.BASE_PATH_FOR_PDF + report.getPdfFilePath() );<br /> exporterXLS.setParameter( JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE );<br /> exporterXLS.setParameter( JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE, Boolean.FALSE );<br /> exporterXLS.setParameter( JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE );<br /> exporterXLS.setParameter( JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE );<br /> exporterXLS.exportReport();</td></tr></tbody></table><br /> <br /> The exportReport method never ends...<br /> <br /> <table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre>/**<br /> * <br /> */<br /> package com.dotbase.jasper.model;<br /> <br /> import java.sql.Connection;<br /> import java.sql.PreparedStatement;<br /> import java.sql.ResultSet;<br /> import java.sql.SQLException;<br /> import java.util.Map;<br /> import java.util.Set;<br /> <br /> import net.sf.jasperreports.engine.JRDataSource;<br /> import net.sf.jasperreports.engine.JRException;<br /> import net.sf.jasperreports.engine.JRField;<br /> <br /> /**<br /> * @author lrobert<br /> * Dataset pour la virtualisation (traîtement de gros rapports)<br /> */<br /> public class DataSource implements JRDataSource<br /> {<br /> private static final int MAX_RESULT_PER_PAGE = 1000;<br /> <br /> private String query;<br /> private Connection connection;<br /> private ResultSet rsReportData;<br /> private int currentPage = 0;<br /> <br /> public DataSource( Map<String, Object> parameters, String query, Connection connection ) throws SQLException<br /> {<br /> //exécuter la requête<br /> connection.setAutoCommit( false );<br /> PreparedStatement statement = connection.prepareStatement( query );<br /> statement.setFetchSize( 100 );<br /> this.rsReportData = Database.executeSelect( statement );<br /> }<br /> <br /> public Object getFieldValue( JRField jrField ) throws JRException<br /> {<br /> try<br /> {<br /> Object field = rsReportData.getObject( jrField.getName() );<br /> return field;<br /> }<br /> catch( SQLException e )<br /> {<br /> throw new JRException( e );<br /> }<br /> }<br /> <br /> private int iNext = 0;<br /> public boolean next() throws JRException<br /> {<br /> try<br /> {<br /> return rsReportData.next();<br /> }<br /> catch( SQLException e )<br /> {<br /> throw new JRException( e );<br /> }<br /> }<br /> <br /> }<br /> </td></tr></tbody></table><br /> <br /> Could somebody help me to solve that ?<br /> <br /> How could I be sure my virtualizer is used ?<br /> <br /> What does the first parameter of the virtualizer ("maxsize") mean ?<br /> <br /> Thank you for your help |
15 Answers:
Posted on June 8, 2007 at 8:30am
I am using virtualizer for jasperreports-1.2.4 and i have observered that from the version of jasperreports-1.2.3 they have made the virtualizer to a single/swap file.
In my case i am running the jasper in RHL(Linux) the virtualizer files are automatically cleared without any user intervension, but the virtualizer files are not deleted unless another report is generated or the same report is regenerated.
In my case i am running the jasper in RHL(Linux) the virtualizer files are automatically cleared without any user intervension, but the virtualizer files are not deleted unless another report is generated or the same report is regenerated.
Posted on June 8, 2007 at 8:30am
I am using virtualizer for jasperreports-1.2.4 and i have observered that from the version of jasperreports-1.2.3 they have made the virtualizer to a single/swap file.
In my case i am running the jasper in RHL(Linux) the virtualizer files are automatically cleared without any user intervension, but the virtualizer files are not deleted unless another report is generated or the same report is regenerated.
In my case i am running the jasper in RHL(Linux) the virtualizer files are automatically cleared without any user intervension, but the virtualizer files are not deleted unless another report is generated or the same report is regenerated.
Posted on June 8, 2007 at 2:49pm
Hi, I've experienced the same problem using the virtualizer.
In debug mode I've seen that the JasperPrint object is generated without errors, the problem (out of memory error) occurs in the exportReport() method on JRHtmlExporter object.
Another strange thing is that I've got the error only when I use JRHtmlExporter or JRXlsExporter and not generating pdf.
Someone could help?
Thank you
In debug mode I've seen that the JasperPrint object is generated without errors, the problem (out of memory error) occurs in the exportReport() method on JRHtmlExporter object.
Another strange thing is that I've got the error only when I use JRHtmlExporter or JRXlsExporter and not generating pdf.
Someone could help?
Thank you
Posted on June 8, 2007 at 3:42pm
Do not set the following parameter to true.
IS_ONE_PAGE_PER_SHEET
If you set this parameter to true, I think jasper engine thinks that all the data should come in one page.
If you set something like that, the effect of pagination will not come into picture since there are no pages.
If that does not work, Can you try exporting the data to PDF or HTML?
IS_ONE_PAGE_PER_SHEET
If you set this parameter to true, I think jasper engine thinks that all the data should come in one page.
If you set something like that, the effect of pagination will not come into picture since there are no pages.
If that does not work, Can you try exporting the data to PDF or HTML?
Posted on June 8, 2007 at 3:46pm
I never exported to Excel.
for the PDF, I do the following and it works.
for the PDF, I do the following and it works.
Code: |
<br /> //Setting Virtualizer for the reports<br /> JRSwapFile swapFile = new JRSwapFile(fileDir, 2048, 2048);<br /> JRSwapFileVirtualizer virtualizer = new JRSwapFileVirtualizer(2, swapFile, true);<br /> finalReportParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);<br /> <br /> //Export<br /> JasperExportManager.exportReportToPdfFile(filedReport,<br /> outputFileName);<br /> </td></tr></tbody></table> |
Posted on June 10, 2007 at 10:12am
Ar eyou setting ignorePagination ?
Code: |
<br /> <jasperReport<br /> name="IPv4SubnetInfo_pdf"<br /> columnCount="1"<br /> printOrder="Vertical"<br /> orientation="Landscape"<br /> pageWidth="1060"<br /> pageHeight="595"<br /> columnWidth="800"<br /> columnSpacing="0"<br /> leftMargin="20"<br /> rightMargin="20"<br /> topMargin="20"<br /> bottomMargin="20"<br /> whenNoDataType="AllSectionsNoDetail"<br /> scriptletClass="com.lucent.qip.reports.IPv4SubnetSummaryScriptlet"<br /> isTitleNewPage="false"<br /> isSummaryNewPage="false"<br /> resourceBundle="catalog/reportsCatalog"<br /> isIgnorePagination="true"><br /> </td></tr></tbody></table><br /> <br /> See the last line....<br /> You should not set that when you want to use virtualizer. |
Posted on June 12, 2007 at 11:56am
Hi,
Thank you for your answers.
I tried to export a PDF instead of an excel spreadsheet.
Without the IS_ONE_PAGE_PER_SHEET parameter and with isIgnorePagination set to "false", it works.
745 files generated by virtualizer in the temp dir, not more than 25MB used by the java process to generate a PDF with 56000 customers (more than 700 pages). Great !
But when I try to do the same except that I export an excel spreadsheet, a lot of files have been generated in the temp dir but the memory used by the java process grown to 250MB and after one hour I killed it before any result has been generated...
Thank you for your help
Post edited by: bugmenot, at: 2007/06/13 12:45
Thank you for your answers.
I tried to export a PDF instead of an excel spreadsheet.
Without the IS_ONE_PAGE_PER_SHEET parameter and with isIgnorePagination set to "false", it works.
745 files generated by virtualizer in the temp dir, not more than 25MB used by the java process to generate a PDF with 56000 customers (more than 700 pages). Great !
But when I try to do the same except that I export an excel spreadsheet, a lot of files have been generated in the temp dir but the memory used by the java process grown to 250MB and after one hour I killed it before any result has been generated...
Thank you for your help
Post edited by: bugmenot, at: 2007/06/13 12:45
Posted on October 11, 2007 at 10:26am
hi,
actually i am facing the same problem.so i want to know how can i use JRDataSource to pass data in chunks till the end of my data.
actually i am new to jasper report.so if i can get sample code implementing JRDataSource and pass the data in chunks....
Suppose i have 6000 record and i want to get this data from db in chunk and use JRDataSource till the end of 6000 record and then i can use datasource to pass in fill report method.
actually i am facing the same problem.so i want to know how can i use JRDataSource to pass data in chunks till the end of my data.
actually i am new to jasper report.so if i can get sample code implementing JRDataSource and pass the data in chunks....
Suppose i have 6000 record and i want to get this data from db in chunk and use JRDataSource till the end of 6000 record and then i can use datasource to pass in fill report method.