OutOfMemoryError:PermGen Space - 在Tomcat上运行Spring的Jasper报告 [英] OutOfMemoryError: PermGen Space -- Jasper Report with Spring running on Tomcat

查看:459
本文介绍了OutOfMemoryError:PermGen Space - 在Tomcat上运行Spring的Jasper报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的Web应用程序遇到了复杂的情况

Our web application encounter a complicated situation

这是由STS / Tomcat 7 开发的Spring应用程序。应用程序与 Jasper report 4.6.0 集成后,它总是抛出`OutOfMemoryError:PermGen Space。然后,让它工作的唯一方法是重新启动应用程序。但过了一段时间它又发生了。
这是异常前的日志:

It is a Spring application developed by STS/Tomcat 7. After the application been integrated with Jasper report 4.6.0, it always throw `OutOfMemoryError: PermGen Space. Then the only way to get it work is to restart the application. But after a while it happen again. Here is log before the exception:

Oct 17, 2012 3:42:27 PM org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Oct 17, 2012 3:42:30 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception

这是异常中我发现 Jasper 的部分:

Here is a section within the exception where I found something about Jasper:

at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:442)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
at org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:240)
at org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:578)
at org.apache.jasper.compiler.TagFileProcessor.access$000(TagFileProcessor.java:49)
at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:655)

以下是情况发生时的一些调查结果:

Here are a few findings when the situation occurs:


  1. 问题可能发生在页面上而没有任何Jasper Report组件。似乎Jasper Report bean在后端处理请求并且响应前端时,一直试图找到一个标记库。通常从日志文件中我可以看到异常不会抛出,直到所有后端操作(JPA管理)完成

  1. The issue can happen on page without any Jasper Report components. It seems the Jasper Report bean is trying to find a tag lib all the time when a request is processed by the back end and responded to the front end. Normally from log file I can see above exception will not throw until all back end operations(JPA management) are complete

在调试模式下运行log4J时,我看到大量信息显示解析/呈现Jasper模板中的所有组件(文本字段,笔,框...),从巨大的日志中有一小部分:

When run log4J on debug mode, I see tons of information showing something like parsing/rendering the all components from Jasper template(textfields, pen, box...), there is a small cut from the huge log:

2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester.sax -- startElement(http://jasperreports.sourceforge.net/jasperreports,textElement,textElement)
2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester --   Pushing body text ''
2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester --   New match='jasperReport/summary/band/textField/textElement'
2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester --   Fire begin() for FactoryCreateRule[className=net.sf.jasperreports.engine.xml.JRTextElementFactory, attributeName=null, creationFactory=net.sf.jasperreports.engine.xml.JRTextElementFactory@12dc6007]
2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester -- [FactoryCreateRule]{jasperReport/summary/band/textField/textElement} New net.sf.jasperreports.engine.design.JRDesignTextField
2012-10-17 15:29:12,025 -- DEBUG -- org.apache.commons.digester.Digester.sax -- ignorableWhitespace()

但是,当对页面的请求执行时,会生成此日志不包含任何Jasper组件。

Still, this log is generated when a request to the page which does not contains any Jasper component.

我做了一些研究,但仍无法找到解决此问题的方法。

I did some research but still cannot find the solution to this issue.


  1. 第一个问题是,即使有一个 jasperreport bean 应用程序为什么它甚至在没有当前服务自动装配时总是运行(意味着当前页面没有任何jasper组件)。是否有这种情况的解决方案/答案?

  1. The first question is even there is a jasperreport bean in the application why it is always running when it is not even autowired with current service(meaning current page doesn't have any jasper component). Is there a solution/answer to this situation?

同样来自异常消息
至少有一个JAR被扫描用于尚未包含TLD的TLD。
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:442)

Also from the exception message At least one JAR was scanned for TLDs yet contained no TLDs. at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:442)

应来自Tomcat, Tomcat从不包含任何JSTL jar ,然后我假设它找不到匹配TLD来解析jasper报告,因此对所有jar进行全面扫描。如果是这样,那么为什么来自 org.apache.commons.digester.Digester 的大量调试日志实际上似乎正忙于解析jasper模板?

should comes from Tomcat, and Tomcat never contains any JSTL jar, then I assume it cannot find a match TLD to parse jasper report hence do a full scan of all jars. If so, then how come there is huge amount of debug logs from org.apache.commons.digester.Digester actually seems busy on parsing the jasper template?

一般情况下,让这个帖子只是试图找出问题的解决方案,并找到为什么Jasper如此的答案在一个地方活动不需要它,以及我们如何让tomcat正确解析模板?

In general, make this thread is just try to figure out a solution to the probelm, and also find an answer to why Jasper is so active on a place doesn't require it, and how we can let tomcat properly parsed the templates?

如果过于冗长,请道歉,并感谢任何提示。

Apologize if too verbose, and thanks for any hints.

推荐答案

感谢大家提供有关此问题的解决方案,我已经根据我的情况确定了问题,这是解决方案:

Thank you everyone for giving solution about this issue, I have identified the problem specifically to my situation and here is the solution:

使用.jasper而不是.jrxml作为模板!

我们知道 .jasper 是一个编译模板以及 .jrxml 是模板的ASCII源代码,所以如果我们使用原始源代码文件(jrxml)作为当前spring应用程序中的模板,然后是le ast spring框架工作必须编译源代码文件。这是一个留给Spring框架的效率问题,因为它是处理编译的jasper bean,并且不能保证编译只执行一次并且只在应用程序启动时才会发生。

As we know .jasper is a compiled template as well as .jrxml is ASCII source code for the template, so if we use raw source code file (jrxml) as template in current spring application then at least spring frame work has to compile the source code file. That's a question of efficiency left to Spring framework as it is the jasper bean to handle the compilation and it is not guaranteed the compilation executed only once and only happens when the application starting.

简而言之,在用.jasper文件替换所有模板后,日志大小已经大大减少,并且还没有看到内存不足的问题。我猜Spring容器可能会消耗大量资源来在运行时将jrxml编译为jasper。因此,Jasper或Spring可能会改进它......

In short, after replace all templates with .jasper file, the log size has been significantly reduced and haven't seen the out of memory issue any more. I guess Spring container may be consume a lot of resource to compile jrxml to jasper at runtime. So it could be something should've improved by Jasper or Spring....

这篇关于OutOfMemoryError:PermGen Space - 在Tomcat上运行Spring的Jasper报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆