我的 JBoss 服务器有一个奇怪的问题:抛出异常:
java.lang.OutOfMemoryError:超出 GC 开销限制
我寻找内存不足的情况,但内存可用性看起来很好:
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 2228224 (2.125MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 805306368 (768.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 176816128 (168.625MB)
used = 110937856 (105.798583984375MB)
free = 65878272 (62.826416015625MB)
62.741932681616014% used
From Space:
capacity = 38207488 (36.4375MB)
used = 27193584 (25.933822631835938MB)
free = 11013904 (10.503677368164062MB)
71.17344118514151% used
To Space:
capacity = 40960000 (39.0625MB)
used = 0 (0.0MB)
free = 40960000 (39.0625MB)
0.0% used
PS Old Generation
capacity = 1434451968 (1368.0MB)
used = 818386128 (780.4738311767578MB)
free = 616065840 (587.5261688232422MB)
57.052180641575866% used
PS Perm Generation
capacity = 113246208 (108.0MB)
used = 109507808 (104.43478393554688MB)
free = 3738400 (3.565216064453125MB)
96.69887401439526% used
有人在看似内存充足的情况下遇到过这个 GC 异常吗?
最佳答案
该错误意味着垃圾收集器付出了巨大的努力,但实际工作却很少,另一个症状是您的应用程序即使没有执行任何繁重的任务,也会变得非常慢,因为它花费了大部分时间运行 GC,但不要只相信我的话,大多数 JDK 都包含许多工具,例如 jstat您可以使用它来监视 GC 的行为,
根据oracle docs :
The parallel 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
但是,它会消除错误消息,但不会消除根本原因,查看您的内存状况看起来并不像是内存不足,因此增加堆大小也无济于事,很可能是问题出在代码中的某个地方,检查应用程序中内存最密集的点,查找可能创建大量对象但不释放它们的地方,并找到一种方法来要么不创建那么多对象,要么释放尽可能多的对象当您不再需要它们时就可以。
关于java - 超出 GC 开销限制,但内存充足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22121061/