Search code examples
javajvmout-of-memory

Why JVM NOT crash after oom?


This maybe an interesting question to ask. In most cases, we do not want jvm crash.

But sometimes the 'oom-ed but not crash' jvm process keeps runing, and may return a value with NULL instead of the correct value. For some scenarios sensitive to value accuracy, this is not acceptable.

So is there way to make jvm DO CRASH after oom? Like some jvm arguments, or alternative approaches to solving this issue to make scenarios keep accuracy.


Solution

  • Found related: Why JVM can recovery from OOM Java heap space by itself

    So, jvm arguments:

    -XX:+CrashOnOutOfMemoryError
    

    Further, also can run a script:

    -XX:OnOutOfMemoryError="/dir/oomKillAndRestart.sh"