jasperreports在大量报告之后内存不足

时间:2015-08-17 16:39:41

标签: java jasper-reports out-of-memory jasperserver

我会避免在JasperReport服务器中出现Out of Memory异常。 拜托,帮助我。

编辑29/08/2015 我在Ubuntu 14.04,java 8上使用JasperReport服务器6.1 相同的结果---详情以下

我写了一个java代码,用于从我的JasperReport Server实例下载(存储在本地文件中)多个pdf报告。 它适用于大约600个报告,之后产生错误500。 在JasperServer日志文件中,我看到内存不足异常。

我的代码可能有错误吗?不这么认为。 相反,我认为jasperReport服务器中存在内存泄漏。

在这里你可以看到我的java代码(类ga.system.jasperserver.ReportExtractor)

    for (ReportParameters aReportParams : listOfReportParameters)
    {
        String filename = "report-"+aReportParams.getParameter1()+ ".PDF";
        jasperreport_url = combineParamsIntoJasperserverUrl(aReportParams);
        URL website = new URL(jasperreport_url);
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        FileOutputStream fos = new FileOutputStream(destPath+"/" +filename);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        fos.close();
        rbc.close();
    }

在这里你可以看到我得到的异常片段

  

java.io.IOException:服务器返回HTTP响应代码:500为URL:http://myjasperserverurl/jasperserver/rest_v2/reports/TestDir/TestReport.pdf?j_username=xxx&j_password=xxx&PARAMETER1=9734&PARAMETER2=0&PARAMETER3=815G21       at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)       at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)       在java.net.URL.openStream(未知来源)       at ga.system.jasperserver.ReportExtractor.extract(ReportExtractor.java:102)   ...   ...   ...

在这里,您可以看到JasperReport Server(catalina.out片段)中的日志

 2015-08-17 18:16:17,091 ERROR RunReportServiceImpl,pool-5-thread-66:511 - caught Throwable exception: Java heap space
java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:2271)
        at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
        at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
        at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.lowagie.text.pdf.OutputStreamCounter.flush(Unknown Source)
        at com.lowagie.text.DocWriter.close(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
        at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
        at com.lowagie.text.Document.close(Unknown Source)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:815)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:513)
        at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.exportToPdf(EngineServiceImpl.java:559)
        at com.jaspersoft.jasperserver.remote.exporters.PdfExporter.exportReport(PdfExporter.java:98)
        at com.jaspersoft.jasperserver.remote.services.impl.ReportExecutorImpl.exportReport(ReportExecutorImpl.java:177)
        at com.jaspersoft.jasperserver.remote.services.impl.RunReportServiceImpl.generateReportOutput(RunReportServiceImpl.java:478)
        at com.jaspersoft.jasperserver.remote.services.impl.RunReportServiceImpl.executeExport(RunReportServiceImpl.java:378)
        at com.jaspersoft.jasperserver.remote.services.impl.RunReportServiceImpl$2.run(RunReportServiceImpl.java:343)
        at com.jaspersoft.jasperserver.api.logging.util.LoggableExecutorService$1.run(LoggableExecutorService.java:59)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:724)

我的服务器中使用的Virtualizer(applicationContext.xml片段)

<bean id="fileVirtualizerFactory" class="com.jaspersoft.jasperserver.api.engine.common.service.impl.FileVirtualizerFactory">
    <property name="maxSize" value="3000"></property>
    <property name="directory" value="${java.io.tmpdir}"></property>
</bean>

我在Ubuntu 14.04上使用JasperReport服务器5.6.0(可靠),java 8

编辑29/08/2015 在Ubuntu 14.04,java 8上使用JasperReport服务器6.1的新测试 同样的结果,新安装的服务器,在生成580 pdf后服务器挂起显示此消息(读取最后一行:&#34;引起:java.lang.OutOfMemoryError:Java堆空间&#34;):

  

org.hibernate.exception.GenericJDBCException:无法初始化   懒惰的属性:   [com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoFileResource#8448]   在   org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)   在   org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)   在   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)   在   org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromDatastore(AbstractEntityPersister.java:831)   在   org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:771)   在   org.hibernate.intercept.AbstractFieldInterceptor.intercept(AbstractFieldInterceptor.java:97)   在   org.hibernate.intercept.cglib.FieldInterceptorImpl.readObject(FieldInterceptorImpl.java:98)   在   com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoFileResource。$ cglib_read_data(未知   来源)at   com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoFileResource.getData(未知   来源)at   com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoFileResource.copyData(未知   来源)at   com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl $ 22.execute(HibernateRepositoryServiceImpl.java:1420)   在   com.jaspersoft.jasperserver.api.metadata.common.service.impl.HibernateDaoImpl.executeCallback(HibernateDaoImpl.java:56)   在   com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.getResourceData(HibernateRepositoryServiceImpl.java:1414)   在sun.reflect.GeneratedMethodAccessor337.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:606)at   org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)   在   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)   在   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)   在com.sun.proxy。$ Proxy32.getResourceData(未知来源)at   sun.reflect.GeneratedMethodAccessor337.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:606)at   org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)   在   com.jaspersoft.jasperserver.api.metadata.user.service.impl.PermissionsPrefetcher.invoke(PermissionsPrefetcher.java:79)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)   在   com.jaspersoft.jasperserver.api.metadata.user.service.impl.PermissionsPrefetcher.invoke(PermissionsPrefetcher.java:79)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)   在   org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:66)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)   在   org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:66)   在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)   在   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)   在com.sun.proxy。$ Proxy38.getResourceData(未知来源)at   com.jaspersoft.jasperserver.api.engine.jasperreports.util.repo.RepositoryConnection.getInputStream(RepositoryConnection.java:114)   在java.net.URL.openStream(URL.java:1037)at   net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:298)   在   net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:100)   在   net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:48)   在   net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:155)   在   net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:176)   在   net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(RepositoryUtil.java:192)   在   net.sf.jasperreports.engine.RenderableUtil.getRenderable(RenderableUtil.java:121)   在   net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:536)   在   net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:472)   在   net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)   在   net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456)   在   net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBackground(JRVerticalFiller.java:1846)   在   net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)   在   net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:152)   在   net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963)   在   net.sf.jasperreports.engine.fill.BaseFillHandle $ ReportFiller.run(BaseFillHandle.java:120)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl $ SynchronousExecutor.execute(EngineServiceImpl.java:886)   在   net.sf.jasperreports.engine.fill.BaseFillHandle.startFill(BaseFillHandle.java:165)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:1804)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl $ SynchronousReportFiller.fillReport(EngineServiceImpl.java:790)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:1731)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl $ ReportFill.runWithDataSource(EngineServiceImpl.java:1086)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl $ ReportFill.runReport(EngineServiceImpl.java:1015)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl $ ReportRunnable.run(EngineServiceImpl.java:908)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl $ SynchronousExecutor.execute(EngineServiceImpl.java:886)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:607)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.executeReportUnitRequest(EngineServiceImpl.java:1937)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.domain.impl.ReportUnitRequest.execute(ReportUnitRequest.java:67)   在   com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.execute(EngineServiceImpl.java:497)   在   com.jaspersoft.jasperserver.remote.services.impl.ReportExecutorImpl $ GenericRunReportStrategy.runReport(ReportExecutorImpl.java:225)   在   com.jaspersoft.jasperserver.remote.services.impl.ReportExecutorImpl.runReport(ReportExecutorImpl.java:127)   在   com.jaspersoft.jasperserver.remote.services.impl.RunReportServiceImpl $ 1.run(RunReportServiceImpl.java:230)   在   com.jaspersoft.jasperserver.api.logging.util.LoggableExecutorService $ 1.run(LoggableExecutorService.java:59)   在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   在java.lang.Thread.run(Thread.java:724)引起:   org.postgresql.util.PSQLException:精美的memoria scaricando我risultati   德拉查询。在   org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1816)   在   org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)   在   org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510)   在   org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)   在   org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)at   org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)   在   org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)   在   org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromDatastore(AbstractEntityPersister.java:802)   ......还有73个   引起:java.lang.OutOfMemoryError:Java堆空间

随时询问您需要的详细信息! 请帮忙 感谢

3 个答案:

答案 0 :(得分:1)

内存管理是Jasper的常见问题。您希望使用Jasper Virtualizer来减少堆负载。

答案 1 :(得分:0)

我遇到了完全相同的问题。大量快速运行的小报告最终消灭了内存。 Eclipse MAT说到GC Root的最短路径是:

No Paths To GC Root I can do anything about...

Here is the Leak Suspect Report:

答案 2 :(得分:0)

最终,这被证明是一个损坏的.jasper文件。重新生成主报表和所有子报表的jasper文件为我解决了问题。