Java 在 CentOS 中禁用 UseGCOverheadLimit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18934146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable the UseGCOverheadLimit in CentOS
提问by Ricky
I need to disable the GC Overhead limit in my CentOS
server. The reason for this is to temporarily prevent java.lang.OutOfMemoryError: GC overhead limit exceeded
exceptions.
我需要在我的CentOS
服务器中禁用 GC 开销限制。这样做的原因是为了暂时防止java.lang.OutOfMemoryError: GC overhead limit exceeded
异常。
But i'm a zero at Linux + Java systems and don't have any clue on how to run this command line: -XX:-UseGCOverheadLimit
但是我对 Linux + Java 系统的了解为零,并且对如何运行此命令行一无所知: -XX:-UseGCOverheadLimit
采纳答案by Dev
You'll need to pass it to the JVM as an argument. You say your hosting a webapp in Apache Tomcat. You can set the environment variable CATALINA_OPTS
to equal -XX:-UseGCOverheadLimit
. You'll have to do this in the script that actually starts tomcat if your running it as a service, and in fact the Tomcat script for CentOS probably has a CATALINA_OPTS
variable in it that you can add to or set.
您需要将它作为参数传递给 JVM。你说你在 Apache Tomcat 中托管了一个 webapp。您可以将环境变量设置CATALINA_OPTS
为 equal -XX:-UseGCOverheadLimit
。如果您将它作为服务运行,则必须在实际启动 tomcat 的脚本中执行此操作,实际上 CentOS 的 Tomcat 脚本中可能有一个CATALINA_OPTS
您可以添加或设置的变量。
That being said, eliminating the ability for the garbage collector to throw an OutOfMemoryError (OOME) due to overhead may not fix the problem. OOME due to overhead basically means the program was not making any useful progress due to the GC operations taking a lot of time. This can happen when free memory is very low and lots of full GC passes have to be made frequently. If you disable the error, its possible the program will simply become unresponsive before finally actually running out of memory in the heap at some undefined point in the future which will still cause an OOME to be thrown for heap space instead of overhead.
话虽如此,消除垃圾收集器由于开销而抛出 OutOfMemoryError (OOME) 的能力可能无法解决问题。由于开销造成的 OOME 基本上意味着由于 GC 操作花费了大量时间,程序没有取得任何有用的进展。当可用内存非常低并且必须经常进行大量完整的 GC 传递时,就会发生这种情况。如果您禁用该错误,则程序可能会在最终在未来某个未定义点实际耗尽堆中的内存之前变得无响应,这仍然会导致为堆空间抛出 OOME 而不是开销。
A better solution would be instead to increase the amount of memory Tomcat is allowed to use by setting using the -Xmx argument (again passed in via CATALINA_OPTS
). -Xmx2g
would set max heap to 2 GiB for instance.
更好的解决方案是通过使用 -Xmx 参数(再次传入 via CATALINA_OPTS
)进行设置来增加允许 Tomcat 使用的内存量。-Xmx2g
例如,将最大堆设置为 2 GiB。