How do I make the JVM exit on ANY OutOfMemoryException even when bad people try to catch it

后端 未结 10 565
醉梦人生
醉梦人生 2020-12-09 16:32

An OOME is of the class of errors which generally you shouldn\'t recover from. But if it is buried in a thread, or someone catches it, it is possible for an application to g

10条回答
  •  误落风尘
    2020-12-09 17:04

    User @dennie posted a comment which should really be its own answer. Newer JVM features make this easy, specifically

    -XX:+ExitOnOutOfMemoryError
    

    to exit on OOME, or to crash:

    -XX:+CrashOnOutOfMemoryError
    

    Since Java 8u92 https://www.oracle.com/java/technologies/javase/8u92-relnotes.html

提交回复
热议问题