Tomcat OutOfMemory问题: java.lang.OutOfMemoryError: GC overhead limit exceeded

问题 :
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

问题产生原因:
根据 sun 的说法: “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.”
jvm gc 行为中超过98% 以上的时间去释放小于 2% 的堆空间时会报这个错误。

处理方法:

Sun 官方申明:
The parallel / 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 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.

  1. 在jvm 启动参数中添加 “-XX:-UseGCOverheadLimit” ,该参数在JDK6 中默认启用 (“-XX:+UseGCOverheadLimit”) 。
    调整后的生产环境中使用的参数为:
JAVA_OPTS='-Xms512m -Xmx4096m -XX:MaxPermSize=128m -XX:-UseGCOverheadLimit -XX:+UseConcMarkSweepGC'
  1. 检查是否有使用了大量内存的代码或死循环
  2. 使用jstat 命令监控 gc 行为是否正常
    jstat监控 gc 的命令格式为:
    stat -gcutil [-t] [-h] [ []]
    mid为 JVM 进程id ,可以用 ps -ef 或 jps -lv 命令查找。
    以下命令为每 1秒钟输出一次 gc 状态,共输入 5次

    S0 S1 E O P YGC YGCT FGC FGCT GCT
    0.00 93.34 85.63 82.95 59.73 1085 33.351 58 4.396 37.748
    98.42 0.00 31.89 83.52 59.73 1088 33.487 58 4.396 37.883
    100.00 85.65 100.00 84.08 59.73 1091 33.554 58 4.396 37.950
    0.00 100.00 54.30 84.49 59.73 1093 33.660 58 4.396 38.057
    98.25 0.00 10.46 85.11 59.73 1096 33.768 58 4.396 38.164
    经过一段时间的观察 ,确认是否正确

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值