日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

What means the error-message 'java.lang.OutOfMemoryError: GC overhead limit exceeded' in Java?

發(fā)布時(shí)間:2023/12/10 java 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 What means the error-message 'java.lang.OutOfMemoryError: GC overhead limit exceeded' in Java? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(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)致異常的原因:沒有足夠的內(nèi)存。

三、解決方案:

1、查看系統(tǒng)是否有使用大內(nèi)存的代碼或死循環(huán)。
2、可以添加JVM的啟動(dòng)參數(shù)來限制使用內(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

  • Triggered 444 times using BAD method
  • Triggered 666 times using WORSE method
  • Triggered 354 times using BETTER method

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ǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。