How to know about OutOfMemory or StackOverflow errors ahead of time

前端 未结 11 1758
余生分开走
余生分开走 2021-02-15 17:10

In Java, is there a way to know that a StackOverflow error or OutOfMemory exception may happen soon?

The OutOfMemory exception m

11条回答
  •  無奈伤痛
    2021-02-15 17:32

    Anticipating Out of Memory Errors

    I'm surprised I didn't see this mentioned in the other posts, but you can use ManagementFactory in Java 5/6 to get at a lot of the memory usage information.

    Look at the platform mbean server page for more information on detecting low memory conditions in Java. I believe you can setup notifiers to call code when memory usage reaches a certain threshold.

提交回复
热议问题