简体   繁体   English

JasperReports fillReport太慢且耗费资源

[英]JasperReports fillReport too slow and resource consuming

I've found that JasperReports is really slow when filling a report from a Java app. 我发现从Java应用程序填充报告时,JasperReports真的很 The program hangs at this line: 程序挂起在这一行:

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

It usually stays there for 3 minutes, consuming up to 300Mb of RAM and 50% CPU . 它通常在那里停留3分钟,消耗高达300Mb的RAM和50%的CPU

  • report is a compiled (.jasper) report that uses 3 subreports. report是一个使用3个子report已编译(.jasper)报表。
  • The datasource is a pretty big XML file (about 100k lines, 1.5Mb) 数据源是一个非常大的XML文件(大约100k行,1.5Mb)
  • The machine is a 3Ghz dual core with 4Gb of RAM 该机器是3Ghz双核,带有4Gb RAM

So, how can I improve report filling performance? 那么,如何提高报表填写性能呢?

The Problem 问题

It seems that the problem is the XPath engine. 似乎问题是XPath引擎。 That is, the library that parses the XML file looking for data. 也就是说,解析XML文件以查找数据的库。

While iReport Designer uses Jaxen , JasperReport uses Xalan . 虽然iReport Designer使用Jaxen ,但JasperReport使用Xalan Xalan is really slow compared to Jaxen (really really slow). 与Jaxen相比,Xalan真的很慢(真的很慢)。

That's why the problem only occurs when filling the report from a Java application and not from iReports. 这就是为什么只在从Java应用程序而不是从iReports填充报表时才会出现问题。

The Solution 解决方案

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): 好吧,解决方案很简单, 只需在Java应用程序中添加以下行来选择Jaxen lib而不是默认的Xalan lib(它已被弃用,但它可以工作):

 
 
 
  
  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");

You will also need to add the Jaxen .jar to your build path. 您还需要将Jaxen .jar添加到构建路径中。 Here is a link: https://mvnrepository.com/artifact/jaxen/jaxen 这是一个链接: https//mvnrepository.com/artifact/jaxen/jaxen


While the report filling was taking 3-5 minutes with Xalan, it now completes in just a few seconds with Jaxen. 虽然填写报告需要花费3-5分钟来使用Xalan,但现在只需几秒钟即可完成Jaxen。

The answer was found here: http://community.jaspersoft.com/questions/536842/jasperreports-too-slow 答案在这里找到: http//community.jaspersoft.com/questions/536842/jasperreports-too-slow
And also here: http://community.jaspersoft.com/wiki/xml-data-source-very-slow-parse 还有这里: http//community.jaspersoft.com/wiki/xml-data-source-very-slow-parse

I was also having this problem when I was exporting pdf, but in my case it seemed to be an infinite loop, because the CPU was hitting 100% when I was trying to generate the JasperReport. 当我导出pdf时,我也遇到了这个问题,但在我的情况下,它似乎是一个无限循环,因为当我试图生成JasperReport时,CPU达到了100%。

After a lot of research I found this link: 经过大量研究后我发现了这个链接:

http://community.jaspersoft.com/questions/527078/infinite-loop-subreport-fill http://community.jaspersoft.com/questions/527078/infinite-loop-subreport-fill

Which my problem was resolved setting my subreports isPrintWhenDetailOverflows="false" . 设置我的子isPrintWhenDetailOverflows="false"时解决了我的问题isPrintWhenDetailOverflows="false"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM