简体   繁体   中英

java.lang.OutOfMemoryError: GC overhead limit exceeded when reading large PDF file using itext PdfReader

I am trying to read a pdf file using PDFReader and re-sequence of pages. It's working with PDF with smaller size but when the size exceeds > 200MB. It fails with below error

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)

I am using itext java 2.1.7 version

Try expanding heap memory of the running Java with -Xmx .

Take a look at https://alvinalexander.com/blog/post/java/java-xmx-xms-memory-heap-size-control/ to know how Xmx is used.

Extending the heap memory using -Xmx might help (as suggested by Pablo) but you should also look at your code and see why it produces that amount of garbage and why your code skims just below the "out of memory" mark. This could be the sign of broken code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM