当我执行JUnit测试时,我得到了这个错误消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?
当我执行JUnit测试时,我得到了这个错误消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?
当前回答
引用Oracle的文章“Java SE 6 HotSpot[tm]虚拟机垃圾收集调优”:
Excessive GC Time and OutOfMemoryError 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.
编辑:看起来有人打字比我快:)
其他回答
通过设置这个选项,稍微增加堆的大小
运行→运行配置→参数→虚拟机参数
-Xms1024M -Xmx2048M
Xms—用于最小限制
Xmx -表示最大限制
@Buhb 我在一个普通的spring-boot web应用程序的main方法中复制了这个过程。代码如下:
public static void main(String[] args) {
SpringApplication.run(DemoServiceBApplication.class, args);
LOGGER.info("hello.");
int len = 0, oldlen=0;
Object[] a = new Object[0];
try {
for (; ; ) {
++len;
Object[] temp = new Object[oldlen = len];
temp[0] = a;
a = temp;
}
} catch (Throwable e) {
LOGGER.info("error: {}", e.toString());
}
}
引起come的示例代码也是来自oracle java8语言规范。
要在IntelliJ IDEA中增加堆大小,请遵循以下说明。这对我很管用。
对于Windows用户,
转到安装IDE的位置并搜索以下内容。
idea64.exe.vmoptions
编辑该文件并添加以下内容。
-Xms512m
-Xmx2024m
-XX:MaxPermSize=700m
-XX:ReservedCodeCacheSize=480m
就是这样!!
根据Java[8]平台,标准版故障处理指南,错误原因:(强调和换行符添加)
[…“GC overhead limit exceeded”表示垃圾收集器一直在运行,Java程序进展非常缓慢。 在垃圾收集之后,如果Java进程花费大约98%的时间进行垃圾收集,如果它回收的堆不到2%,并且到目前为止已经连续进行了5次(编译时间常数)垃圾收集,则抛出Java .lang. outofmemoryerror。[…]
Increase the heap size if current heap is not enough. If you still get this error after increasing heap memory, use memory profiling tools like MAT ( Memory analyzer tool), Visual VM etc and fix memory leaks. Upgrade JDK version to latest version ( 1.8.x) or at least 1.7.x and use G1GC algorithm. . The throughput goal for the G1 GC is 90 percent application time and 10 percent garbage collection time Apart from setting heap memory with -Xms1g -Xmx2g , try -XX:+UseG1GC -XX:G1HeapRegionSize=n -XX:MaxGCPauseMillis=m -XX:ParallelGCThreads=n -XX:ConcGCThreads=n
看看更多关于G1GC的相关问题
G1上的Java 7 (JDK 7)垃圾收集和文档 生产环境中的Java G1垃圾收集 Oracle technetwork关于GC优化的文章
您还可以通过将此添加到gradle中来增加内存分配和堆大小。属性文件:
org . gradle。jvmargs = -Xmx2048M -XX: MaxHeapSize \ = 32g
它不需要2048M和32g,你想要多大就有多大。