Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

It usually stays there for 3 minutes, consuming up to 300Mb of RAM and 50% CPU.

  • 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
362 views
Welcome To Ask or Share your Answers For Others

1 Answer

The Problem

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

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

That's why the problem only occurs when filling the report from a Java application and not from 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):

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. Here is a link: 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.

The answer was found here: http://community.jaspersoft.com/questions/536842/jasperreports-too-slow
And also here: http://community.jaspersoft.com/wiki/xml-data-source-very-slow-parse


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...