Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryError

 
sunil kumbs
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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)
at java.util.zip.ZipFile.<init>(ZipFile.java:203)
at java.util.zip.ZipFile.<init>(ZipFile.java:234)
at com.ibm.ws.classloader.SinglePathClassProvider$2.run(SinglePathClassProvider.java:242)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:63)
at com.ibm.ws.classloader.SinglePathClassProvider.getClassBytesFromJar(SinglePathClassProvider.java:233)
at com.ibm.ws.classloader.SinglePathClassProvider.getClassBytes(SinglePathClassProvider.java:178)
at com.ibm.ws.classloader.CompoundClassLoader.findClass(CompoundClassLoader.java:457)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:389)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)


Note: My server heap size is, Initial: 128mb Maximum: 512mb, WAS version 6.1.0.15 , SunOS, version 5.9, Java version = 1.5.0_13


Is there any other alternative than increasing the heap size?

Thanks in advance
 
Vicki Amin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
sunil kumbs
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vicki,

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.
 
Vicki Amin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?

 
Paul Clapham
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)


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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic