manishamauni Posted March 29, 2007 Share Posted March 29, 2007 Hi All,I am using jasper reports for generating different reports in my web application.All my reports make use of subreports. After 40-50 min my web application starts throwing OutOfMemory. I have tried all the GC optimizations (http://java.sun.com/docs/hotspot/gc1.4.2/) without much success. On checking thread dump I found that subreport filler threads are getting locked. These locked threads are holding up the memory and gradually forcing application towards Out of memory. //--------------------------------------------------------------------------------------- "template_11 subreport filler" daemon prio=1 tid=0x0862ac88 nid=0x2813 waiting for monitor entry [0x813e9000..0x813ea228] at sun.awt.font.NativeFontWrapper.getFontMetrics(Native Method) at java.awt.Font.defaultLineMetrics(Font.java:1595) at java.awt.Font.getLineMetrics(Font.java:1662) at java.awt.font.TextMeasurer.initAll(TextMeasurer.java:223) at java.awt.font.TextMeasurer.<init>(TextMeasurer.java:149) at java.awt.font.LineBreakMeasurer.<init>(LineBreakMeasurer.java:292) at java.awt.font.LineBreakMeasurer.<init>(LineBreakMeasurer.java:259) at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:259) at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:220) at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:528) at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:534) at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:345) at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:311) at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:275) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1291) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:631) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(JRVerticalFiller.java:248) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:132) - locked <0x8a315458> (a net.sf.jasperreports.engine.fill.JRVerticalFiller) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:758) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:498) at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:63) at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:137) at java.lang.Thread.run(Thread.java:534) //--------------------------------------------------------------------------------------- Are there any specific things we need to keep in mind while using sureports?I saw one at http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=8&id=3709#3709 However my reports don’t have that issue. Would appreciate any help in resolving this issue. I am running the web server on Linux and I am using- j2sdk1.4.2_12- jasperreports-1.2.5- Apache Tomcat 5.0.28 ThanksManisha Link to comment Share on other sites More sharing options...
aniruddh4u Posted March 29, 2007 Share Posted March 29, 2007 Hi can you place to code how your generating report from java like there are 2-3 different approach of creating report from jrxml.. 1. JasperPrint jasperPrint = new JasperPrint();Connection conn = null;Map inputParameters = new HashMap();inputParameters.put("sometitle","first report");conn = your database connection you get from your driver (using jt400)JasperReport jasperReport = JasperCompileManager.compileReport("input.jrxml");jasperPrint = JasperFillManager.fillReport(jasperReport,inputParameters, conn);// for a pdfJasperExportManager.exportReportToPdfFile(jasperPrint, outputFile.pdf); or 2. String path = request.getRealPath("jasper"); path = path + "/AgingReportForCoverageArea.jasper"; HashMap map = new HashMap(); JasperPrint jasperPrint = JasperFillManager.fillReport(path, map, connectDB()); //Block to check viewer selected String viewer = request.getParameter("viewType"); if(viewer.equalsIgnoreCase("0")){ // Open report in HTML response.setContentType("text/html"); JRHtmlExporter exporter = new JRHtmlExporter(); exporter = new JRHtmlExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,response.getWriter()); request.getSession().setAttribute( ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint); exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, new HashMap()); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,request.getContextPath() + "/images?image="); // In This "images" is name of folder which contain images exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME,request.getRealPath("images")); exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR,true); exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND,true); exporter.exportReport(); }else{ // Open report in PDF response.setContentType("application/pdf"); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,response.getOutputStream()); exporter.exportReport(); } cause compiling jrxml in java code itself every time when running report might use you memory and make ur application slow Link to comment Share on other sites More sharing options...
manishamauni Posted March 29, 2007 Author Share Posted March 29, 2007 Thanks Aniruddh !! I am also trying to avoid frequent compilation of ".jrxml". I compile all the report template at the time of web application startup and store them in a bean class (ReportTemplates) . //------------------------------------------------------------------- private JasperReport loadAndCompileReport(String reportXmlFile) { logger.info("loading and compiling " + reportXmlFile + "....."); InputStream reportStream = this.getClass().getResourceAsStream(reportXmlFile); JasperReport compliedReport = null; try { JasperDesign reportDesign = JRXmlLoader.load(reportStream); reportDesign.setPageHeight(595); reportDesign.setPageWidth(842); reportDesign.setOrientation(JRReport.ORIENTATION_LANDSCAPE); compliedReport = JasperCompileManager.compileReport(reportDesign); } catch (Exception exp) { logger.error(exp.getMessage()); } return compliedReport; } //------------------------------------------------------------------- whenever I get a report request I get the corressponding "JasperReport" using following function... //------------------------------------------------------------------- private JasperPrint getReport(int reportId, boolean ignorePagination, String rptHeader, final List formattedData) { JasperPrint currentReport = null; Hashtable srConfigData = BootstrapServlet.getStyleReportConfigData(); int subReportId = Integer.parseInt(((ReportConfigData) srConfigData .get(reportId + "")).getSubReportId()); logger.info("sunReportId [" + reportId + "] " + subReportId); Map parameters = new HashMap(); try { //JRFileVirtualizer virtualizer = new JRFileVirtualizer(10,"marstemp"); JRGzipVirtualizer virtualizer = new JRGzipVirtualizer(10); // get the "JasperReport" from the bean ReportTemplates reportTemplates = ReportTemplates.getInstance(); JasperReport jasperReportMain = reportTemplates.getStyleMainReport(); logger.info("Subreport id for the report(" + reportId + ") - " + subReportId); JasperReport jasperReportSubreport = reportTemplates.getStyleSubReport(subReportId); parameters.put("rptHeader", rptHeader); parameters.put("ProjectDetailSubreport", jasperReportSubreport); parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); if (ignorePagination) { parameters.put("IS_IGNORE_PAGINATION", Boolean.TRUE); } else { parameters.put("IS_IGNORE_PAGINATION", Boolean.FALSE); } currentReport = JasperFillManager.fillReport(jasperReportMain,parameters, new JRBeanCollectionDataSource(formattedData)); //virtualizer.cleanup(); } catch (Exception exp) { logger.error(exp.getMessage()); exp.printStackTrace(); } return currentReport; }//------------------------------------------------------------------- And depending on the file format type (html/pdf/rtf/....) I pass it to the corresponding function. The function I use for pdf export is as follows... //-------------------------------------------------------------------private void downloadToPdf(HttpServletRequest request, HttpServletResponse response, final JasperPrint jasperPrint, String fileName) { try { logger.info("Downloading (pdf)- " + fileName + " for the user -" + request.getSession().getAttribute(ReportPortalconstantsIfc.USER_NAME)); response.setHeader("Content-Disposition", "attachment; filename=""+ fileName + ".pdf""); response.setContentType("application/pdf"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.exportReport(); byte[] content = baos.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); } catch (Exception exp) { logger.error(exp.getMessage()); }} //---------------------------------------------------- Link to comment Share on other sites More sharing options...
aniruddh4u Posted March 29, 2007 Share Posted March 29, 2007 Hi.. Even Loading and Compilation task as well as Report Design task you can do mannually using tools like iReport.... aniruddh Link to comment Share on other sites More sharing options...
manishamauni Posted March 29, 2007 Author Share Posted March 29, 2007 Sure that can be done using Ireport...but again it will not solve.. just delay the Out of memory...and thread problem... Link to comment Share on other sites More sharing options...
aniruddh4u Posted March 29, 2007 Share Posted March 29, 2007 i guess it can be a final solution .. cause we hv report inventory project running for a investment bank firm but never got deadlock on production environment... ----Aniruddh Link to comment Share on other sites More sharing options...
javierar Posted July 31, 2015 Share Posted July 31, 2015 I have de same problem, and it seems to be DATA DRIVEN, when i have a too long string in one of my report textfield jasper seems to struggle fitting it .thats why i have the save stack trace than you"FeuilleDeTravail subreport filler"at sun.awt.font.NativeFontWrapper.getFontMetrics(Native Method)at java.awt.Font.defaultLineMetrics(Font.java:1595)at java.awt.Font.getLineMetrics(Font.java:1662)at java.awt.font.TextMeasurer.initAll(TextMeasurer.java:223)at java.awt.font.TextMeasurer.<init>(TextMeasurer.java:149)at java.awt.font.LineBreakMeasurer.<init>(LineBreakMeasurer.java:292)at java.awt.font.LineBreakMeasurer.<init>(LineBreakMeasurer.java:259)at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:259)at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:220)at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:528)with jasperreports 5.5.0, jdk 1.6.33 and jboss 4.3Aris 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