views:

2468

answers:

6

Often, I found OutOfMemoryException on IBM Websphere Application Server. I think this exception occur because my application retrieve Huge data from database. So, I limit all query don't retreive data more than 1000 records and set JVM of WAS follow

+ Verbose garbage collection
+ Maximum Heap size = 1024 (RAM on my server is 16 GB and now I already change to 8192)
+ Debug arguments = -Djava.compiler=NONE -Xdebug -Xnoagent  
                    -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7777
+ Generic JVM arguments = -Dsun.rmi.dgc.server.gcInterval=60000 
                          -Dsun.rmi.dgc.client.gcInterval=60000 -Xdisableexplicitgc  
                          -Dws.log=E:\WebApp\log -Dws.log.level=debug
(ws.log and ws.log.level are my properties)

And I found heapdump, javacore and snap files in profiles folder I think them can tell me about cause of problem but I don't know how to read/use heapdump, javacore and snap files.

Please tell me how to prevent/avoid/fix OutOfMemoryException. Thanks

A: 

The answer to this is dependent on the message associated with the OutOfMemoryException. You can also try -XX:MaxPermSize=... and set it to something larger like 256m.

Also, if you have a recursive function somewhere, that may be causing a stack overflow.

If you can, please post the message associated with the exception. Stacktrace might also help.

James Schek
OK, I will try again :D
Fuangwith S.
+3  A: 

If you want to look at the heap dump files, IBM offers tools to analyze them here.

Adam Crume
A: 

Try to reproduce the problem locally so you can use a tool like JProfiler to debug it. Even if you can't force an OOM locally, chances are you'll see the memory increase in JProfiler. Then you take snapshots and look for classes that aren't being garbage collected. It's not an exact science, but it's much easier than looking through an IBM heapdump. However, if you have to, the old way of examining a heap dump was with HeapRoots. It may depend on the version you're on. I do know that some versions of the IBM JDK have problems with compacting so even if you have plenty of memory, you can get an OOM because there's not a large enough fragment available.

Brian Deterling
A: 

I assume your using hibernate/JPA as a persistence provider? Are you using a second level cache? If so have you considered evicting large results sets from the cache?

A: 

The question is hard to answer if we don't know what kind of OutOfMemoryError it is; permgen and heapspace are two very different beasts.

I was chasing a perm-gen for many months on JBoss, though the that particular type of problem was general to any application server that reloaded web applications on the fly. The saga is documented here.

Those heap-dumps you have... could be that you can analyze them in Eclipse MAT.

Christian Vest Hansen
+1  A: 

"Thanks for the memory" is a good article about the JVMs use of memory, which might help to analyse this problem...

Thanks to bwalliser for this link

dertoni