Ztyx Ztyx - 7 months ago 63
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"

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

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