JasperReports fillReport太慢且耗费资源 [英] JasperReports fillReport too slow and resource consuming

查看:1321
本文介绍了JasperReports fillReport太慢且耗费资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Java应用程序填写报告时发现JasperReports真的。该程序挂起在这一行:

I've found that JasperReports is really slow when filling a report from a Java app. The program hangs at this line:

print = JasperFillManager.fillReport(report, parameters, xmlDataSource);

它通常会在 3分钟内停留,消耗高达300Mb的RAM和50%的CPU


  • report 是一个编译(.jasper)报告,使用3个子报告。

  • 数据源是一个非常大的XML文件(大约10万行,1.5Mb)

  • 该机器是3Ghz双核心4Gb内存

  • report is a compiled (.jasper) report that uses 3 subreports.
  • The datasource is a pretty big XML file (about 100k lines, 1.5Mb)
  • The machine is a 3Ghz dual core with 4Gb of RAM

那么,如何提高报表填写性能呢?

So, how can I improve report filling performance?

推荐答案

问题



似乎问题是XPath引擎。也就是说,解析XML文件寻找数据的库。

The Problem

It seems that the problem is the XPath engine. That is, the library that parses the XML file looking for data.

当iReport Designer使用 Jaxen 时,JasperReport使用 Xalan 。与Jaxen相比,Xalan真的很慢(真的很慢)。

While iReport Designer uses Jaxen, JasperReport uses Xalan. Xalan is really slow compared to Jaxen (really really slow).

这就是为什么问题只发生在从Java应用程序而不是iReports填充报告时。

That's why the problem only occurs when filling the report from a Java application and not from iReports.

嗯,解决方案很简单,只需在Java应用程序中添加以下行即可选择Jaxen lib而不是默认的Xalan lib(它已被弃用,但它可以工作):

Well, the solution is simple, just add the following line in your Java application to select Jaxen lib instead of the default Xalan lib (it's deprecated, but it works):

JRProperties.setProperty("net.sf.jasperreports.xpath.executer.factory",
    "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");

编辑:该行已被弃用,我找到了设置属性的正确方法:

EDIT: That line was deprecated, I've found the correct way to set properties:

DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.xpath.executer.factory",
    "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");

您还需要将Jaxen .jar添加到构建路径中。这是一个链接: https://mvnrepository.com/artifact/jaxen/jaxen

You will also need to add the Jaxen .jar to your build path. Here is a link: https://mvnrepository.com/artifact/jaxen/jaxen

虽然使用Xalan填写报告需要3-5分钟,但现在只需几秒钟即可完成Jaxen。

答案在这里找到: http://community.jaspersoft.com/questions/536842/jasperreports-too-slow

还在这里: http://community.jaspersoft.com/wiki/xml-data-source-very-slow-parse

这篇关于JasperReports fillReport太慢且耗费资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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