[英]Jaspersoft reports, “Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread ”BAM subreports #1“”
I have a simple Jasper report, that I simplified it at maximum and now it should give me a blank page but instead it gives me a "Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "BAM subreports #1"".我有一个简单的 Jasper 报告,我最大程度地简化了它,现在它应该给我一个空白页,但它给了我一个“异常:java.lang.OutOfMemoryError 从线程“BAM 子报告 #1”中的 UncaughtExceptionHandler 引发的错误。
Jasper takes a long time to think and in the end displays the memory error. Jasper想了很久,最终显示memory错误。
The blockage that causes the supposed memory leak appears in the JasperFillManager.fillReport.导致假定的 memory 泄漏的阻塞出现在 JasperFillManager.fillReport 中。
This is no a problem related to the allocated memory, I tried to increase the memory with the options "-Xms1140m -Xmx1140m" and it seems to think forever for a very simple report.这与分配的 memory 无关,我尝试使用选项“-Xms1140m -Xmx1140m”来增加 memory,它似乎永远为一个非常简单的报告而思考。
The report contains:该报告包含:
So the structure of the datasource is所以数据源的结构是
BAMHeader= [ <-- main report is here and contains a single record
BAMResults= [
item1, <-- for this test a single record is in BAMResults
]
]
The xml for the main report is:主要报告的 xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="BAM" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="13acf49e-4913-4d1b-bccc-113817ad15d1">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="BAMResults" class="java.util.List"/>
<detail>
<band height="192">
<subreport overflowType="NoStretch">
<reportElement x="2" y="150" width="530" height="30" uuid="e7898571-e6f1-4348-a3f8-2871775dd207"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{BAMResults})]]></dataSourceExpression>
<subreportExpression><![CDATA["results.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
The xml for the subreport is:子报告的 xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="results" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="34cb40f6-7f10-4c98-81fe-75101acc9691">
<queryString>
<![CDATA[]]>
</queryString>
<detail>
<band height="72" splitType="Stretch"/>
</detail>
</jasperReport>
The java source code of the main class is: java主class的源代码为:
public class JasperBAM {
public static void main(String[] args) {
try {
List<BAMHeader> bhs = BAMHeader.getBAMHeader();
Map<String, Object> parameters = new HashMap<>();
System.err.println("Start fill");
JasperPrint jasperPrint = JasperFillManager.fillReport("JasperReports/BAM.jasper", parameters, new JRBeanCollectionDataSource(bhs));
System.err.println("Stop fill");
OutputStream outputStream = new FileOutputStream(new File("BAM.pdf"));
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
} catch (Exception ex) {
Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
The class that will populate the main report is:将填充主报告的 class 是:
public class BAMHeader {
private List<BAMResult> BAMResults = new ArrayList<>();
public static List<BAMHeader> getBAMHeader() {
try {
List<BAMHeader> bhs = new ArrayList<>();
BAMHeader bh = new BAMHeader();
bh.setBAMResults();
bhs.add(bh);
return bhs;
} catch (Exception ex) {
Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
public void setBAMResults() {
System.err.println("Start setBAMResults");
this.BAMResults = BAMResult.getBAMResults();
System.err.println("Stop setBAMResults");
}
public List<BAMResult> getBAMResults() {
System.err.println("Start getBAMResults");
return this.BAMResults;
}
}
The class that will populate the subreport is:将填充子报告的 class 是:
public class BAMResult {
public static List<BAMResult> getBAMResults() {
try {
List<BAMResult> brs = new ArrayList<>();
BAMResult nt = new BAMResult();
brs.add(nt);
return brs;
} catch (Exception ex) {
Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
}
As a final observation, if I delete the single record from BAMResults the memmory problem dissapears.作为最后的观察,如果我从 BAMResults 中删除单个记录,内存问题就会消失。
UPDATE: I use jasperreports-6.17.0.jar更新:我使用 jasperreports-6.17.0.jar
UPDATE: Apache netbeans profiler iamges更新:Apache netbeans 分析仪图像
If I replace in the main report XML the line如果我在主报告中替换 XML 行
<subreport overflowType="NoStretch">
with the line用线
<subreport>
than the problem dissapeares.比问题消失。
But this looks like a Jasper BUG.但这看起来像 Jasper BUG。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.