JVM运行报错:GC overhead limit exceeded

今天在折腾OOM和java的4种引用类型的时候,在运行过程中JVM报了一个错误:

java.lang.OutOfMemoryError: GC overhead limit exceeded 


这个错误平时遇到的概率很少很少,今天无意中遇到了,这里做个记录。oracle/sun官网的解释是:

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.


我使用的是JDK1.6.0_37和JDK_1.7.0_60版本,这2个版本中JVM默认启动的时候-XX:+UseGCOverheadLimit,即启用了该特性。这其实是JVM的一种推断,如果垃圾回收耗费了98%的时间,但是回收的内存还不到2%,那么JVM会认为即将发生OOM,让程序提前结束。当然我们可以使用-XX:-UseGCOverheadLimit,关掉这个特性。


不太明白为什么JDK要提供这么个参数。当我们遇到这个错误只能说明:要么是内存空间不足,要么是存在内存泄露。这个时候对我们有意义的,其实就是heap dump,我们可以分析堆内存的情况,从而诊断出是否代码存在问题。

我们知道如果在启动JVM的时候设置了如下的参数,那么JVM崩溃的时候会打印出heap dump。

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:/  

个人感觉,如果真的发生了"GC overhead limit exceeded"错误,那么其实离实际的OOM已经不远了,所以让JVM做个预测提前结束,感觉意义不大。




  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值