gpt4 book ai didi

java - 捕获 OutOfMemoryError 是个坏主意吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:37:59 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Catching java.lang.OutOfMemoryError

OutOfMemoryError是:

Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector

Java 说:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.

这感觉就像在听:

If you are drowning, be reasonable: you should not try to swim upwards to keep your head above water. Death is typically resulting from abnormal conditions.

让我们想象一个正在运行服务的场景。由于某种原因,同一台服务器上的另一个应用程序正在消耗大量内存,导致您的服务出现意外的 OOM。尝试减少此服务的内存消耗以保持对用户可用是个坏主意吗?

或者在抛出 OOM 后,JVM 级别是否发生了更根本的事情,阻止了此类解决方案的实现?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com