This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I've an application where I generate a report and export it to excel. The list is quite huge and contains more than 8000 records. But while generating the report I'm getting the below mentioned error. Can anybody please help me with this.
Uncaught exception thrown in one of the service methods of the servlet: Exception thrown : java.lang.OutOfMemoryError at java.util.zip.ZipFile.open(Native Method)
Note: My server heap size is, Initial: 128mb Maximum: 512mb, WAS version 126.96.36.199 , SunOS, version 5.9, Java version = 1.5.0_13
Is there any other alternative than increasing the heap size?
Thanks in advance
Many of life's failures are people who did not realize how close they were to success when they gave up. -- Thomas A. Edison
How are you exporting it to Excel? One of the workarounds would be (in case your excel is not too complicated) be to write the data to the file system in a CSV format and then push it using a servlet to the browser with application/vnd.ms-excel as the MIME type. This way you would not be utilizing a lot of heap memory. In case the excel size is huge; you could consider zipping it up before you push it to the browser.
From the error stack trace I've posted above you can see i'm trying to zip it before pushing it to browser, and thats when I get this OutofMemory error.
Joined: Aug 31, 2005
I didn't realize that you were facing errors during the zipping process since you mentioned in your post that you get the error while generating the report.
I have used this snippet of code earlier in projects where we have zipped up decent sized excel files (data represented as objects) - upto 30 megs with a max heap size set to 512 megs. Is this something similiar that you have on your end?
sunil kumbs wrote:From the error stack trace I've posted above you can see i'm trying to zip it before pushing it to browser...
Actually that stack trace shows you are trying to load a class, presumably from a jar file. Lines from the stack trace like this one:
tell me that. However your technique for "zipping it before pushing it to browser" is using more memory than necessary. Don't write the entire zipped data to a byte array, just wrap the GZIPOutputStream around the servlet response's output stream and write to that. And what's the ObjectOutputStream for?