How to detect Out Of Memory condition?

Jaromir Hamala picture Jaromir Hamala · Aug 25, 2009 · Viewed 10.1k times · Source

I have an application running on Websphere Application Server 6.0 and it crashes nearly every day because of Out-Of-Memory. From verbose GC is certain there are the memory leaks(many of them)

Unfortunately the application is provided by external vendor and getting things fixed is slow & painful process. As part of the process I need to gather the logs and heapdumps each time the OOM occurs.

Now I'm looking for some way how to automate it. Fundamental problem is how to detect OOM condition. One way would be to create shell script which will periodically search for new heapdumps. This approach seems me a kinda dirty. Another approach might be to leverage the JMX somehow. But I have little or no experience in this area and don't have much idea how to do it.

Or is in WAS some kind of trigger/hooks for this? Thank you very much for every advice!

Answer

Mark picture Mark · Aug 25, 2009

You can pass the following arguments to the JVM on startup and a heap dump will be automatically generated on an OutOfMemoryError. The second argument lets you specify the path for the heap dump file. By using this at least you could check for the existence of a specific file to see if a heap dump has occurred.

-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=<value>