how to generate thread dump java on out of memory error

Jigar picture Jigar · May 7, 2010 · Viewed 19.9k times · Source
  • does java 6 generate thread dump in addition to heap dump (java_pid14941.hprof)

  • this is what happened to one of my applications.

    java.lang.OutOfMemoryError: GC overhead limit exceeded Dumping heap to java_pid14941.hprof ...

  • I did find ava_pid14941.hprof in working directory, but didn't find any file which contains thread dump. I need to know what all the threads were doing when I got this OutOfMemory error.

  • Is there any configuration option which will generate thread dump in addition to heap dump on out of memory exception?

Answer

Jim Bethancourt picture Jim Bethancourt · May 20, 2010

If you're in a Linux/Unix environment you can do this:

-XX:OnOutOfMemoryError="kill -3 pid"

This way you don't have to have your application generate periodic thread dumps and you'll get a snapshot when it actually chokes.