Ztyx Ztyx - 1 year ago 167
Java Question

How can I restart JVM on OutOfMemoryError _after_ making a heap dump?

I know about the

JVM parameter. I also know about
-XX:OnOutOfMemoryError="cmd args;cmd args"
and that
kill -3 <JVM_PID>
will request a heap dump.

Question: How can I make sure that I, on
, first make a full heap dump and then force a restart (or kill) after the dump is done? Is my best bet
-XX:OnOutOfMemoryError="kill -3 %p;sleep <time-it-takes-to-dump>;kill -9 %p"

Answer Source
java -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError="kill -9 %p" TestApp

JVM will dump heap first, and then execute OnOutOfMemoryError commands (proof).

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