wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Performance
Bookmark "OutOfMemoryError during the pdf report generation" Watch "OutOfMemoryError during the pdf report generation" New topic
Author

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.

FYI
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?


thanks
V
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
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.

thanks
V
ganesh roti
Greenhorn

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

thanks
V
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

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
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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.

Bill
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

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.


thanks
V
 
wood burning stoves
 
subject: OutOfMemoryError during the pdf report generation