Java heap dump & shut down - what order?

前端 未结 5 1341
暖寄归人
暖寄归人 2021-02-07 08:35

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

5条回答
  •  一整个雨季
    2021-02-07 08:52

    In Java version 8u92 the VM arguments

    • -XX:+ExitOnOutOfMemoryError
    • -XX:+CrashOnOutOfMemoryError

    were added, see the release notes.

    ExitOnOutOfMemoryError
    When you enable this option, the JVM exits on the first occurrence of an out-of-memory error. It can be used if you prefer restarting an instance of the JVM rather than handling out of memory errors.

    CrashOnOutOfMemoryError
    If this option is enabled, when an out-of-memory error occurs, the JVM crashes and produces text and binary crash files.

    Enhancement Request: JDK-8138745 (parameter naming is wrong though JDK-8154713, ExitOnOutOfMemoryError instead of ExitOnOutOfMemory)

提交回复
热议问题