java.lang.OutOfMemoryError:jasper 报告中的 Java 堆空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1587098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:11:04  来源:igfitidea点击:

java.lang.OutOfMemoryError: Java heap space in jasper report

javajasper-reports

提问by stanley

When i export content in doc format then i get java heap space error,

当我以 doc 格式导出内容时,出现 java 堆空间错误,

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Unknown Source)
    at java.io.ByteArrayOutputStream.write(Unknown Source)
    at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
    at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
    at sun.nio.cs.StreamEncoder.write(Unknown Source)
    at sun.nio.cs.StreamEncoder.write(Unknown Source)
    at java.io.OutputStreamWriter.write(Unknown Source)
    at java.io.Writer.write(Unknown Source)

回答by msp

Best add a

最好加一个

-XX:+HeapDumpOnOutOfMemoryError

to create heapdump whenever an OutOfMemoryError occurrs, and then analyse the heap dump with e.g. Eclipse Memory Analyzerwhich will show you the amount of objects and usually clearly identifies the objects causing the OutOfMemory Error.

每当发生 OutOfMemoryError 时创建堆转储,然后使用例如Eclipse Memory Analyzer分析堆转储,它会显示对象的数量并通常清楚地识别导致 OutOfMemory 错误的对象。

回答by BalusC

java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space

Java is simply running out of memory. It cannot allocate more memory anymore. The remnant of the stacktrace is irrelevant, it just happen to happen exactly during the array copy action. It could have happened anywhere.

Java 只是内存不足。它不能再分配更多的内存。堆栈跟踪的剩余部分无关紧要,它恰好在数组复制操作期间发生。它可能发生在任何地方。

Apparently you're trying to generate a report based on an extremely large dataset (thousands or tenthousands of records maybe), or you've supplied JVM too little memory. You should then just ensure that JVM has enough memory to handle all that data. The default is 128MB or 256MB, depending on JVM and environment used. Start to double that amount using the -Xmxargument for the JVM.

显然,您正在尝试基于极大的数据集(可能有数千或数万条记录)生成报告,或者您提供的 JVM 内存太少。然后,您应该确保 JVM 有足够的内存来处理所有这些数据。默认为 128MB 或 256MB,具体取决于使用的 JVM 和环境。开始使用-XmxJVM的参数将该数量加倍。

E.g.

例如

java -Xmx512M (other arguments here)

You may also want to profileyour application to check how many memory it is actually using and then optimize the argument for that.

您可能还想分析您的应用程序以检查它实际使用了多少内存,然后为此优化参数。

On the other hand, if you're processing really a lotof data, then consider doing it in parts, e.g. first the first thousand records and then the second thousand records, etcetera.

另一方面,如果您确实要处理大量数据,则考虑分部分进行处理,例如首先处理前一千条记录,然后再处理第二千条记录,等等。

回答by BalusC

If you dataset is huge, then you need to page the report generation itself. I was doing some research large dataset for jasper reports and found thisarticle quite informative.

如果您的数据集很大,那么您需要对报告生成本身进行分页。我正在为 jasper 报告做一些研究大型数据集,发现这篇文章非常有用。

回答by Vladimir Ivanov

You should go with Virtualizers feature of jasper reports. See an article here.

您应该使用 jasper 报告的 Virtualizers 功能。请参阅此处的文章。

回答by Tom Neyland

Try increasing the memory that the JVM Starts with, and can use as its MAX.

尝试增加 JVM 启动的内存,并可用作其 MAX。

Add these arguments to the launching of your program

将这些参数添加到程序的启动中

-Xms500M

-Xms500M

Replace the 500 with however many megs you want the JVM to start with.

将 500 替换为您希望 JVM 以多少兆字节开始。

-Xmx500M

-Xmx500M

Replace the 500 with however many megs you want the maximum memory the JVM can use to be.

将 500 替换为您希望 JVM 可以使用的最大内存数量。

回答by sinuhepop

Is not needed a great amount of memory for usual reports. Is your document so big?

通常报告不需要大量内存。你的文件有这么大吗?

Maybe Jasper Reports goes in an infinite loop. Modify log4j level in order to get more clues about what's occurring. Try to delete some parts to know where it gets stuck.

也许 Jasper Reports 陷入了无限循环。修改 log4j 级别以获得有关正在发生的事情的更多线索。尝试删除一些部分以了解它卡在哪里。

I've used Jasper Reports and get some errors like this. Sometimes Jasper Reports behaviour is, well, strange.

我使用了 Jasper Reports 并遇到了一些这样的错误。有时,Jasper Reports 的行为很奇怪。

Good luck.

祝你好运。

回答by Varun Bansal

You can change memory params in setenv.bat file. below is the path for the same.

您可以在 setenv.bat 文件中更改内存参数。下面是相同的路径。

jasperhome/apache-tomcat/bin/setenv.bat

jasperhome/apache-tomcat/bin/setenv.bat

here you can change JvmMsand JvmMxparameters as per your requirement. Once change the param you need to restart the jasper server. one way to do this is by restart jasper services by task manager.

在这里,您可以根据需要更改JvmMsJvmMx参数。更改参数后,您需要重新启动 jasper 服务器。一种方法是通过任务管理器重新启动 jasper 服务。