bugmenot Posted June 6, 2007 Share Posted June 6, 2007 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&Itemid=5 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"«») ); parameters.put( JRParameter.REPORT_VIRTUALIZER, virtualizer ); DataSource dataSource = new DataSource( parameters, jasperReport.getQuery().getText(), connection ); JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, dataSource ); //----------------------------------------------------- JRXlsExporter exporterXLS = new JRXlsExporter(); exporterXLS.setParameter( JRXlsExporterParameter.JASPER_PRINT, jasperPrint ); //exporterXLS.setParameter( JRXlsExporterParameter.OUTPUT_STREAM, output ); exporterXLS.setParameter( JRXlsExporterParameter.OUTPUT_FILE_NAME, PDFReportCreator.BASE_PATH_FOR_PDF + report.getPdfFilePath() ); exporterXLS.setParameter( JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE ); exporterXLS.setParameter( JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE, Boolean.FALSE ); exporterXLS.setParameter( JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE ); exporterXLS.setParameter( JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE ); exporterXLS.exportReport(); The exportReport method never ends... Code:[code]/** * */package com.dotbase.jasper.model;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Map;import java.util.Set;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;/** * @author lrobert * Dataset pour la virtualisation (traîtement de gros rapports) */public class DataSource implements JRDataSource{ private static final int MAX_RESULT_PER_PAGE = 1000; private String query; private Connection connection; private ResultSet rsReportData; private int currentPage = 0; public DataSource( Map<String, Object> parameters, String query, Connection connection ) throws SQLException { //exécuter la requête connection.setAutoCommit( false ); PreparedStatement statement = connection.prepareStatement( query ); statement.setFetchSize( 100 ); this.rsReportData = Database.executeSelect( statement ); } public Object getFieldValue( JRField jrField ) throws JRException { try { Object field = rsReportData.getObject( jrField.getName() ); return field; } catch( SQLException e ) { throw new JRException( e ); } } private int iNext = 0; public boolean next() throws JRException { try { return rsReportData.next(); } catch( SQLException e ) { throw new JRException( e ); } }} Could somebody help me to solve that ? How could I be sure my virtualizer is used ? What does the first parameter of the virtualizer ("maxsize") mean ? Thank you for your help Link to comment Share on other sites More sharing options...
arunvishvin Posted June 7, 2007 Share Posted June 7, 2007 What is the version of your JR?? Link to comment Share on other sites More sharing options...
bugmenot Posted June 7, 2007 Author Share Posted June 7, 2007 arunvishvin wrote:What is the version of your JR?? Oh yes, sorry. I am using jasperreports-1.3.2.jar Thank you for your help. Link to comment Share on other sites More sharing options...
bugmenot Posted June 7, 2007 Author Share Posted June 7, 2007 Same result with jasperreports-1.3.3... Link to comment Share on other sites More sharing options...
bugmenot Posted June 8, 2007 Author Share Posted June 8, 2007 anybody can help ? Do you use virtualizers ? Where am I wrong ? Thank you for your help Link to comment Share on other sites More sharing options...
arunvishvin Posted June 8, 2007 Share Posted June 8, 2007 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. Link to comment Share on other sites More sharing options...
arunvishvin Posted June 8, 2007 Share Posted June 8, 2007 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. Link to comment Share on other sites More sharing options...
bugmenot Posted June 8, 2007 Author Share Posted June 8, 2007 Thank you for your answer. So you mean jasper actually uses the virtualizer... So why do I continue get OutOfMemoryError ? Link to comment Share on other sites More sharing options...
milli Posted June 8, 2007 Share Posted June 8, 2007 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 Link to comment Share on other sites More sharing options...
raffimd Posted June 8, 2007 Share Posted June 8, 2007 Do not set the following parameter to true.IS_ONE_PAGE_PER_SHEETIf 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? Link to comment Share on other sites More sharing options...
raffimd Posted June 8, 2007 Share Posted June 8, 2007 I never exported to Excel. for the PDF, I do the following and it works.Code://Setting Virtualizer for the reportsJRSwapFile swapFile = new JRSwapFile(fileDir, 2048, 2048);JRSwapFileVirtualizer virtualizer = new JRSwapFileVirtualizer(2, swapFile, true); finalReportParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);//ExportJasperExportManager.exportReportToPdfFile(filedReport, outputFileName); Link to comment Share on other sites More sharing options...
raffimd Posted June 10, 2007 Share Posted June 10, 2007 Ar eyou setting ignorePagination ?Code:<jasperReport name="IPv4SubnetInfo_pdf" columnCount="1" printOrder="Vertical" orientation="Landscape" pageWidth="1060" pageHeight="595" columnWidth="800" columnSpacing="0" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenNoDataType="AllSectionsNoDetail" scriptletClass="com.lucent.qip.reports.IPv4SubnetSummaryScriptlet" isTitleNewPage="false" isSummaryNewPage="false" resourceBundle="catalog/reportsCatalog" isIgnorePagination="true"> See the last line....You should not set that when you want to use virtualizer. Link to comment Share on other sites More sharing options...
milli Posted June 11, 2007 Share Posted June 11, 2007 Thank you for your suggestions, I've set the parameters.But I've still problem only for big reports and only for html and excel, how many records can jasperreport output?I'm using JRBeanCollectionDatasource. Thank you again. Link to comment Share on other sites More sharing options...
raffimd Posted June 11, 2007 Share Posted June 11, 2007 If your dataset is large, you should not go for JRBeanCollectionDatasource. Instead implement the JRDataSource, fetch the data in chunks/pages and return the data through next() and getFieldValue() APIs. Link to comment Share on other sites More sharing options...
bugmenot Posted June 12, 2007 Author Share Posted June 12, 2007 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 helpPost edited by: bugmenot, at: 2007/06/13 12:45 Link to comment Share on other sites More sharing options...
samaresh Posted October 11, 2007 Share Posted October 11, 2007 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now