我们正在运行一个有时会“卡住”的 Java 应用程序,因为某些线程几乎使用了所有堆。 尽管 JVM 执行的 Full GC 持续时间超过 60 秒,但应用程序从未因 OutOfMemoryError 而死。
我从 Java 文档中读到:
The throughput collector will throw an out-of-memory exception if too much time is being spent doing garbage collection. For example, if the JVM is spending more than 98% of the total time doing garbage collection and is recovering less than 2% of the heap, it will throw an out-of-memory expection.
我想了解更多关于这 98% 的时间意味着什么的信息(时间范围是什么?),以及是否可以降低此值,即如果应用程序将 90% 的时间花在 GC 上,则抛出 OOME并且不能释放超过 10% 的堆。
目标是确保应用程序在 OOME 时死掉(而不是只运行 GC),这样我们就可以在 OOME 上生成转储。
以下是我们使用的内存和 GC 设置(操作系统是 Solaris):
-Xms2048m -Xmx2048m \
-Xmn512m \
-XX:PermSize=256m
-XX:MaxPermSize=256m \
-XX:+UseParNewGC
-XX:ParallelGCThreads=16 \
-XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled \
-XX:+DisableExplicitGC \
-XX:+PrintGC
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps \
-XX:+PrintClassHistogram \
-Xloggc:/gcmonitor.log \
-XX:+HandlePromotionFailure \
-XX:SurvivorRatio=4
-XX:TargetSurvivorRatio=90
-XX:MaxTenuringThreshold=10 \
-XX:+UseTLAB
-XX:TLABSize=32k
-XX:+ResizeTLAB \
-XX:+UseMPSS \
最佳答案
I would like more information about what this 98% of time means (what is the time frame ?)
这个问题的答案:GC overhead limit exceeded建议是 1 分钟。
is possible to lower this value
再次查看上述问题,看起来您可以使用 GCTimeLimit
和 GCHeapFreeLimit
参数。
关于java - JVM 到底什么时候抛出 OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8913902/