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

后端 未结 10 530
醉梦人生
醉梦人生 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 16:57

    You could use the MemoryPoolMXBean to be notified when a program exceeds a set heap allocation threshold.

    I haven't used it myself but it should be possible to shut down this way when the remaining memory gets low by setting an allocation threshold and calling System.exit() when you receive the notification.

提交回复
热议问题