5

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.

3 Answers 3

7

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]

Sign up to request clarification or add additional context in comments.

Comments

5

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.)

Comments

0

As stated in the Oracle documentation:

The -XX:+HeapDumpOnOutOfMemoryError command-line option tells the HotSpot VM to generate a heap dump when an allocation from the Java heap or the permanent generation cannot be satisfied. There is no overhead in running with this option, and so it can be useful for production systems where OutOfMemoryError takes a long time to surface.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.