gpt4 book ai didi

java - JasperReport-锁定虚拟化上下文时中断

转载 作者:行者123 更新时间:2023-12-02 03:38:13 24 4
gpt4 key购买 nike

您好,我是 JasperReport 的新手,我正在尝试生成一个大型报告。我的报告有很多子报告,但 968 条记录生成全部正确,但当记录超过 1048 时,就会出现异常。我使用 Virtualizacion 生成报告,并将 PDF 文件导出到我的计算机。这是异常(exception)情况:

Grave:   net.sf.jasperreports.engine.JRRuntimeException: Interrupted     while locking virtualization context
at net.sf.jasperreports.engine.fill.JRVirtualizationContext.lock(JRVirtualizationContext.java:524)
at net.sf.jasperreports.engine.base.ElementsBlock.lockContext(VirtualizableElementList.java:237)
at net.sf.jasperreports.engine.base.ElementsBlock.afterExternalization(VirtualizableElementList.java:517)
at net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer.virtualizeData(JRAbstractLRUVirtualizer.java:590)
at net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer.evict(JRAbstractLRUVirtualizer.java:402)
at net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer.requestData(JRAbstractLRUVirtualizer.java:548)
at net.sf.jasperreports.engine.base.ElementsBlock.ensureData(VirtualizableElementList.java:463)
at net.sf.jasperreports.engine.base.ElementsBlock.ensureDataAndTouch(VirtualizableElementList.java:432)
at net.sf.jasperreports.engine.base.ElementsBlock.writeObject(VirtualizableElementList.java:582)
at sun.reflect.GeneratedMethodAccessor384.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at net.sf.jasperreports.engine.base.JRVirtualPrintPage.writeObject(JRVirtualPrintPage.java:274)
at sun.reflect.GeneratedMethodAccessor383.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at java.util.ArrayList.writeObject(ArrayList.java:762)
at sun.reflect.GeneratedMethodAccessor257.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
at java.util.Collections$SynchronizedCollection.writeObject(Collections.java:2081)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at net.sf.jasperreports.engine.util.JRSaver.saveObject(JRSaver.java:75)
at net.sf.jasperreports.engine.util.JRSaver.saveObject(JRSaver.java:55)
at net.sf.jasperreports.engine.JasperFillManager.fillToFile(JasperFillManager.java:230)
at net.sf.jasperreports.engine.JasperFillManager.fillToFile(JasperFillManager.java:124)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:666)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1220)
at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
at net.sf.jasperreports.engine.fill.JRVirtualizationContext.lock(JRVirtualizationContext.java:520)
... 94 more

更新
我正在使用 JRSwapVirtualization,如下一段代码所示:

我的报告(包)由4个子报告组成(其中2个只有一页,另一个可能有一页或多页),要求是为特定街道的每人从这4个子报告生成一个包。例如,“ST. Julia AV”有 984 人,该应用程序为街上的每个人生成一个包。有了这个数量,一切都是正确的,但是当人们增加报告导出崩溃时。

详情
我正在使用 Glassfish 开发 WEBAPP,我为服务器的 JVM 分配了 3GB RAM。

try {
cn = dataSourceReports.getConnection();
JRSwapFile swapFile = new JRSwapFile(System.getProperty("java.io.tmpdir"), 30, 10);
virtualizer = new JRSwapFileVirtualizer(1, swapFile, true);
parameters.put(JRParameter.REPORT_VIRTUALIZER,virtualizer);
JasperPrint jp = JasperFillManager.fillReport(ROUTE_REPORT,parameters, cn);
JasperExportManager.exportReportToPdfFile(jp,
"D://placePackage.pdf");

cn.close();
} catch (SQLException e) {
e.printStackTrace();
}finally{
virtualizer.cleanup();
}

最佳答案

这在很大程度上取决于您初始化虚拟化的方式以及您使用的虚拟化类型。

例如,如果您使用具有非常高的页面设置的 JRFileVirtualizer,例如

JRFileVirtualizer virtualizer = new JRFileVirtualizer(100, "myDir");

每 100 页内容才会写入文件。将此值设置为非常低的值并逐步提高可能会有所帮助。

JRFileVirtualizer virtualizer = new JRFileVirtualizer(1, "myDir");

编辑:

查看 JRSwapFile 的初始化后, block 大小的值看起来非常小。尝试类似以下示例的操作:

new JRSwapFile(System.getProperty("java.io.tmpdir"), 2048, 32);

完成后,您应该逐步升级虚拟器中保存的页面,直到您对结果感到满意并且不会出现问题,例如

virtualizer = new JRSwapFileVirtualizer(5, swapFile, true);

甚至

virtualizer = new JRSwapFileVirtualizer(100, swapFile, true);

关于java - JasperReport-锁定虚拟化上下文时中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37172323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com