This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryError during the pdf report generation

 
az ziz
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your heap size set to? (-Xmx flag on the command line)
 
Gokul Nanthakumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
az ziz
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic