theeggman85 theeggman85 - 1 year ago 96
Java Question

Java heap dump & shut down - what order?

I would like to detect an

, take a heap dump, and automatically exit the Java program. Say I have the following command-line arguments for my JVM:

-XX:OnOutOfMemoryError="kill -9 %p"
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/tmp

Which happens first? Does the process dump memory and then quit, or the other way around?

Ram Ram
Answer Source

I would rather rely on calling into a script that handles the ordering more deterministically i.e.

-XX:OnOutOfMemoryError="/<SomeStandardLocation>/" will then employ a method to find the pid of the current process. One simple way to identify the pid is to use the log file location your process is writing to

lsof | grep /var/tmp/<yourlogfileName> | cut -d " " -f1 | uniq

I will then use jmap to dump and kill -9 subsequently

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download