fillReport函数期间的PermGen Space错误

时间:2012-03-19 23:37:19

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

我在执行

时遇到以下PermGen空格错误
    JasperFillManager.fillReport(reportFile.getPath(), parameters, conn);

在以下代码块中:

    compileFileName = parameters.get("reportName").toString();
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

    ServletContext context = (ServletContext) externalContext.getContext();
    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();

    ReportConfigUtil.compileReport(context, getCompileDir(), getCompileFileName());

    File reportFile = new File(ReportConfigUtil.getJasperFilePath(context, getCompileDir(), getCompileFileName()+".jasper"));


    Class.forName(ReportsConstants.DRIVER);
    Connection conn = DriverManager.getConnection(ReportsConstants.DB_ACCESS_URL, ReportsConstants.DB_ACCESS_USER_NAME, ReportsConstants.DB_ACCESS_PASSWORD);

    parameters.put("BaseDir", reportFile.getParentFile());

    JasperPrint jasperPrint =  JasperFillManager.fillReport(reportFile.getPath(), parameters, conn);

我收到的错误如下:

    Caused by: javax.faces.el.EvaluationException: java.lang.OutOfMemoryError: PermGen space
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 19 more
    Caused by: java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)

我的开发环境如下:JSF,PrimeFaces,Hibernate,JasperReports,Sybase。

你的朋友建议我做些什么来解决这个问题?

1 个答案:

答案 0 :(得分:1)

增加perm gen空间会使这个问题消失。添加以下参数会将其增加到128米

-XX:MaxPermSize=128m

我不确定您是否可以在代码中做很多事情来减少正在消耗的perm gen空间量,因此我认为任何解决方案都与更改JVM运行时参数有关。

你也可以考虑尝试

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled