【发布时间】:2021-03-24 16:54:24
【问题描述】:
我正在尝试使用 PDFReader 读取 pdf 文件并重新排序页面。它适用于尺寸较小但尺寸超过 200MB 的 PDF。它失败并出现以下错误
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at com.lowagie.text.pdf.MappedRandomAccessFile$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.lowagie.text.pdf.MappedRandomAccessFile.clean(Unknown Source)
at com.lowagie.text.pdf.MappedRandomAccessFile.close(Unknown Source)
at com.lowagie.text.pdf.RandomAccessFileOrArray.close(Unknown Source)
at com.lowagie.text.pdf.PRTokeniser.close(Unknown Source)
at com.lowagie.text.pdf.PdfReader.readPdf(Unknown Source)
at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
我使用的是itext java 2.1.7版本
【问题讨论】:
-
需要调试细节:代码和PDF。此外,iText 2.1.7 已有十多年的历史,并且不再受支持。
-
此外,您可能还想检查为 JVM 分配了多少堆内存并使用 VisualVM 之类的工具对其进行分析。
-
是的 itext 2.1.7 太旧了,但由于许可部分用于商业用途,我不能妥协使用这个版本
-
您使用什么 Java 版本?您是否已使用 -Xmx VM 参数?如果使用,它们是什么?
-
是的,我们确实定义了 -Xmx 参数,即 2048m,我观察到如果值设置为低于 4096m,它会崩溃