Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Heap Dump automatically when Java process Hits OutOfMemory Error?

I have Java program running in Linux platform and it crash quite often;at this situation, I would like to have heapdump automatically.

Does anyone have script/method to create a Heap Dump Automatically when Java process Hits "OutOfMemory Error" on Linux?

I would appreciate your help.

like image 467
Thiyagarajan Varadharaj Avatar asked Dec 18 '22 17:12

Thiyagarajan Varadharaj


2 Answers

To take a heap dump automatically, edit {installation directory}/bin/setenv.sh and add this to the JAVA_OPTS:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=[path to heap dump]

like image 162
MS Srikkanth Avatar answered Dec 21 '22 10:12

MS Srikkanth


Have a look at this page for JVM options, specifically:

-XX:HeapDumpPath=./java_pid.hprof Path to directory or filename for heap dump. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)

-XX:-HeapDumpOnOutOfMemoryError Dump heap to file when java.lang.OutOfMemoryError is thrown. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)

like image 34
M A Avatar answered Dec 21 '22 09:12

M A