Behavior of a Java process in case of OutOfMemoryError

后端 未结 3 1177
暗喜
暗喜 2020-12-19 05:16

What would be the behavior of a Java program on getting OutOfMemoryError. Is there any defined behavior? Will the process crash or would it go into wait/sleep state?

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-19 06:08

    You can't determine the state of program when OutOfMemoryError occurs. If you are not catching Throwable then your program will terminate with the stacktrace. Even if you are catching Throwable, you should call System.exit since there is no point in recovering from it. "Error" is generally thrown by JVM, as oppose to Exception, which is application/programmer specific.

提交回复
热议问题