错误 java.lang.OutOfMemoryError:超出 GC 开销限制 [英] Error java.lang.OutOfMemoryError: GC overhead limit exceeded

查看:31
本文介绍了错误 java.lang.OutOfMemoryError:超出 GC 开销限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行 JUnit 测试时收到此错误消息:

I get this error message as I execute my JUnit tests:

java.lang.OutOfMemoryError: GC overhead limit exceeded

我知道 OutOfMemoryError 是什么,但是 GC 开销限制是什么意思?我该如何解决这个问题?

I know what an OutOfMemoryError is, but what does GC overhead limit mean? How can I solve this?

推荐答案

此消息意味着由于某种原因垃圾收集器占用了过多的时间(默认情况下占进程所有 CPU 时间的 98%)并且恢复得很慢每次运行的内存很少(默认为堆的 2%).

This message means that for some reason the garbage collector is taking an excessive amount of time (by default 98% of all CPU time of the process) and recovers very little memory in each run (by default 2% of the heap).

这实际上意味着您的程序停止执行任何进度,并且一直忙于只运行垃圾收集.

This effectively means that your program stops doing any progress and is busy running only the garbage collection at all time.

为了防止您的应用程序在没有完成任何事情的情况下占用 CPU 时间,JVM 会抛出此 Error 以便您有机会诊断问题.

To prevent your application from soaking up CPU time without getting anything done, the JVM throws this Error so that you have a chance of diagnosing the problem.

我见过这种情况发生的极少数情况是,一些代码在已经非常受内存限制的环境中创建了大量临时对象和大量弱引用对象.

The rare cases where I've seen this happen is where some code was creating tons of temporary objects and tons of weakly-referenced objects in an already very memory-constrained environment.

查看 Java GC 调优指南,该指南适用于各种 Java 版本并包含有关此特定问题的部分:

Check out the Java GC tuning guide, which is available for various Java versions and contains sections about this specific problem:

  • Java 11 调优指南 有专门的部分介绍了过度 GC不同的垃圾收集器:
    • Java 11 tuning guide has dedicated sections on excessive GC for different garbage collectors:
      • for the Parallel Collector
      • for the Concurrent Mark Sweep (CMS) Collector
      • there is no mention of this specific error condition for the Garbage First (G1) collector.

      这篇关于错误 java.lang.OutOfMemoryError:超出 GC 开销限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆