java - 超出 GC 开销限制

标签 java garbage-collection jvm

JVM 用于抛出“java.lang.OutOfMemoryError:GC 开销限制超出”的采样时间是多少? 我知道您可以使用参数 GCTimeLimit 和 GCHeapFreeLimit 控制 98% 和 2%,但是采样时间是多少?

最佳答案

来自 Java SE 6 HotSpot[tm] Virtual Machine Garbage Collection Tuning

以下

Excessive GC Time and OutOfMemoryError

The concurrent collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

The policy is the same as that in the parallel collector, except that time spent performing concurrent collections is not counted toward the 98% time limit. In other words, only collections performed while the application is stopped count toward excessive GC time. Such collections are typically due to a concurrent mode failure or an explicit collection request (e.g., a call to System.gc()).

结合下面的一段

One of the most commonly encountered uses of explicit garbage collection occurs with RMIs distributed garbage collection (DGC). Applications using RMI refer to objects in other virtual machines. Garbage cannot be collected in these distributed applications without occasionally collection the local heap, so RMI forces full collections periodically. The frequency of these collections can be controlled with properties. For example,

java -Dsun.rmi.dgc.client.gcInterval=3600000

-Dsun.rmi.dgc.server.gcInterval=3600000 specifies explicit collection once per hour instead of the default rate of once per minute. However, this may also cause some objects to take much longer to be reclaimed. These properties can be set as high as Long.MAX_VALUE to make the time between explicit collections effectively infinite, if there is no desire for an upper bound on the timeliness of DGC activity.

似乎意味着确定 98% 的评估期为一分钟,但它可能可以在 Sun 的 JVM 上通过正确的定义进行配置。

当然,其他解释也是可能的。

关于java - 超出 GC 开销限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4371505/

相关文章:

java - PNGj,元数据不被保存

java - 使用 Java 访问 Java Applet 非静态方法

performance - 我可以从 F# 交互式计时输出中提取哪些有用信息?

java - 在 64 位 JVM 上运行 Openfire

java - InputStream 和字节数组生成器?

java - Weblogic 错误 : Caused by: weblogic. transaction.internal.AppSetRollbackOnlyException:在事务上调用 setRollbackOnly

.net - .NET中的GC期间安全地暂停线程

c# - 使用单例模式时,我的公共(public)类应该返回私有(private)实例还是公共(public)实例?

java - JNI 失败并返回 'Error occurred during initialization of VM'

java - JDK 的本地方法是如何加载的?