Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate thread dump java on out of memory error

  • 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?

like image 759
Jigar Avatar asked May 07 '10 10:05

Jigar


People also ask

How do you get heap dump on OutOfMemoryError?

The parameter -XX:+HeapDumpOnOutOfMemoryError can be set to enable heap dump when the JVM runs out of memory. You have set this parameter in the BW_JAVA_OPTS environment variable. By default the heapdump snapshot gets stored in the root location with the name java_pid1.

How do I resolve out of memory exception?

1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

How do I force heap dump?

Start the administrative console. In the navigation pane, click Troubleshooting > Java dumps and cores. Select the server_name for which you want to generate the heap dump. Click Heap dump to generate the heap dump for your specified server.


1 Answers

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

-XX:OnOutOfMemoryError="kill -3 %p"

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

With %p, you don't need to pass the PID, JVM will automatically pick the correct process id as mentioned here.

like image 127
Jim Bethancourt Avatar answered Sep 28 '22 05:09

Jim Bethancourt