The moose likes Performance and the fly likes OutOfMemoryError during the pdf report generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "OutOfMemoryError during the pdf report generation" Watch "OutOfMemoryError during the pdf report generation" New topic

OutOfMemoryError during the pdf report generation

az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
hei there,

In my web application, the user searches for a policy though the web interface, which i will find in the file server, the policy is in the form of pdf file, and respond them. there is also an option to search multiple policies, find them and print them in single attempt. in this case, i find those policy pdf files from a file server and combine them into one single pdf and write the bytes to the servlet output stream. in this case OutOfMemoryError is raised if more files are attempted to print. the combined single pdf file may run to hundreds of pages. i use itext to combine the pdfs.

I combine all the pdf
I am using clustered WAS server in AIX environment.

how do i solve this memory problem, as the client is specific in improving the speed and number of report printed?
Does increasing the JVM size may improve the situation, if so what if more files are combined and printed?
does data compression improve this situation? or is it an overhead?

Kees Jan Koster
JavaMonitor Support

Joined: Mar 31, 2009
Posts: 251
What is your heap size set to? (-Xmx flag on the command line)

Java-monitor, JVM monitoring made easy <- right here on Java Ranch
Gokul Nanthakumar
Ranch Hand

Joined: May 11, 2010
Posts: 56
if the number of request is going to be high, Instead of combining the files in run time, combine them offline and place in the same folder, based on the user request you can serve the file what ever he want. (this will iff the number of files going to be limited)
az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
thanks for your replies.

I cannot combine the pdfs offline as the requested reports may be random, each time. but I can only combine the list of reports requested runtime, no matter how old it is.

ganesh roti

Joined: May 16, 2010
Posts: 17
try to use ReferenceQueue when one file is written on the stream..i didn't got the corrrect context in your problem. But definitely if you use this approach before jvm throws any OutOfMemory it releases all the object that you have enqued in the ReferenceQueue and thus you can avoid this outOfmemory
az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
ok let me try to explain it again.

I have a scheduler which runs periodically and generate reports in the form of pdf, fetching data from the database and save it to the file server. This part is separate.

Now in the web interface of the project the end user searches for a/few "policy(ies)", ie the report, an application in the web module will find the corresponding reports in the file server. as more reports are found the results of the search fetches few files. As the user requirement is to view these reports in a single pdf file, i merge all the found pdf report files using itext library and write them to the ServletOutputStream. the avg size of a pdf file will be around 300kb. say for example i have 30 - 40 reports searched, i combine them into a single pdf file using the itext and write the bytes into the stream. in this scenario while i merge the pdf, say in between 25th or 30th pdf, the server throwing the OutOfMemory exception.
i felt its due to the size of the combined file?

hope i had explained things clearly

Joe Ess

Joined: Oct 29, 2001
Posts: 8843

Vijay Veeraraghavan.V wrote:
i felt its due to the size of the combined file?

That is quite possible. Have you performed any tests to confirm your suspicion?
You still haven't answered Kees Jan Koster's question, which is another important piece to the puzzle. If the problem is the amount of memory available at one time (as opposed to a memory leak, where the memory is consumed and never returned), increasing the heap may be your solution.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
Are there other computers on your network you could hand off the pdf combining job to?

Due to the (presumed) random nature of request coming to your server, there is always a possibility of "simultaneous" requests overloading the server no matter how much memory it has.

Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30136

Also, have you considered using something other than iText. iText is very powerful. An API/library that just merges PDFs may use a lot less memory since that is all it has to do.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
az ziz
Ranch Hand

Joined: Dec 17, 2008
Posts: 50
thanks for all your replies.
the jvm inside which the WAS runs has 1024 MB memory.
as Mr. Jeanne suggests, i am trying with other libraries such as pdfbox and PJX.

It is sorta covered in the JavaRanch Style Guide.
subject: OutOfMemoryError during the pdf report generation
Similar Threads
iText Silent Print
print all docs togather without interruption from other computers
How to search a file in a file server and serve from servlets?
Performance Optimization with JS Files........
Writing large files to the servletoutputstream in chunks