What means the error-message 'java.lang.OutOfMemoryError: GC overhead limit exceeded' in Java?
轉(zhuǎn)國(guó)內(nèi)的:
一、異常如下:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
二、解釋:
JDK6新增錯(cuò)誤類型。當(dāng)GC為釋放很小空間占用大量時(shí)間時(shí)拋出。
一般是因?yàn)槎烟 ?dǎo)致異常的原因:沒(méi)有足夠的內(nèi)存。
三、解決方案:
1、查看系統(tǒng)是否有使用大內(nèi)存的代碼或死循環(huán)。
2、可以添加JVM的啟動(dòng)參數(shù)來(lái)限制使用內(nèi)存:-XX:-UseGCOverheadLimit
?
?
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.
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.
Check out this article for details (specifically this part).
?
?
The GC throws this exception when too much time is spent in garbage collection for too little return, eg. 98% of CPU time is spent on GC and less than 2% of heap is recovered.
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.
You can turn this off with the command line option -XX:-UseGCOverheadLimit
More info here
?
?
| It's usually the code. Here's a simple example: import java.util.*;?? public class GarbageCollector {? ? ? ? public static void main(String... args) {? ? ? ? ? ? System.out.printf("Testing...%n");? ? ? ? ? List<Double> list = new ArrayList<Double>();? ? ? ? ? for (int outer = 0; outer < 10000; outer++) {? ? ? ? ? ? ? ? // list = new ArrayList<Double>(10000); // BAD? ? ? ? ? ? ? // list = new ArrayList<Double>(); // WORSE? ? ? ? ? ? ? list.clear(); // BETTER? ? ? ? ? ? ? ? for (int inner = 0; inner < 10000; inner++) {? ? ? ? ? ? ? ? ? list.add(Math.random());? ? ? ? ? ? ? }? ? ? ? ? ? ? ? if (outer % 1000 == 0) {? ? ? ? ? ? ? ? ? System.out.printf("Outer loop at %d%n", outer);? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? ? System.out.printf("Done.%n");? ? ? }? }? Using java 1.6.0_24-b07 On a Windows7 32 bit. java -Xloggc:gc.log GarbageCollector Then look at gc.log
Now granted, this is not the best test or the best design but when faced with a situation where you have no choice but implementing such a loop or when dealing with existing code that behaves badly, choosing to reuse objects instead of creating new ones can reduce the number of times the garbage collector gets in the way... |
轉(zhuǎn)載于:https://www.cnblogs.com/diyunpeng/archive/2011/05/23/2054500.html
總結(jié)
以上是生活随笔為你收集整理的What means the error-message 'java.lang.OutOfMemoryError: GC overhead limit exceeded' in Java?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 谷歌云盘超大文件快速下载方法
- 下一篇: 超星尔雅学习通情商与智慧人生 答案 满分