I know about the -XX:+HeapDumpOnOutOfMemoryError
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 OutOfMemoryError
, 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"
?
I bet the runtime sets a specific errorlevel on crash. Check for that return code and rerun the program in that case. You should perhaps put that into a script.
The sun jre allows you to heap dump on oome, perhaps openjdk does too.
JVM will dump heap first, and then execute OnOutOfMemoryError commands (proof).
If you just want to shutdown you can use one of the following parameters:
-XX:+ExitOnOutOfMemoryError
-XX:+CrashOnOutOfMemoryError
The VM arguments were added in Java version 8u92, see the release notes.
Enhancement Request: JDK-8138745 (parameter naming is wrong though JDK-8154713,
ExitOnOutOfMemoryError
instead ofExitOnOutOfMemory
)