当前位置: 首页 > news >正文

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

转国内的:

一、异常如下:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

二、解释:
JDK6新增错误类型。当GC为释放很小空间占用大量时间时抛出。
一般是因为堆太小。导致异常的原因:没有足够的内存。

三、解决方案:

1、查看系统是否有使用大内存的代码或死循环。
2、可以添加JVM的启动参数来限制使用内存:-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...

相关文章:

  • 大家好
  • getBoundingClientRect() 来获取页面元素的位置
  • 索引(二)
  • 《优秀网页设计速查与赏析》464
  • 分享Silverlight/WPF/Windows Phone一周学习导读(05月16日-05月21日)
  • 2015 UESTC 数据结构专题D题 秋实大哥与战争 SET的妙用
  • Sass和Compass入门
  • Operations Manager 2007 R2系列之域控客户端代理安装
  • C# 使用微软的Visual Studio International Pack 类库提取汉字拼音首字母
  • 控件基本属性Padding, Margins, Align...
  • IBM Tivoli Management Framework默认设置漏洞
  • 在 Java SE 6 中监视和诊断性能问题
  • WinCE6.0流驱动开发的两种方法及驱动加载失败问题解决
  • android 深入研究ratingbar自定义
  • 新的Windows Azure SDK for PHP 3.0版本现已推出
  • [ JavaScript ] 数据结构与算法 —— 链表
  • Apache Pulsar 2.1 重磅发布
  • DataBase in Android
  • IE报vuex requires a Promise polyfill in this browser问题解决
  • Java程序员幽默爆笑锦集
  • Vue UI框架库开发介绍
  • 爱情 北京女病人
  • 从零开始在ubuntu上搭建node开发环境
  • 动态魔术使用DBMS_SQL
  • 构建工具 - 收藏集 - 掘金
  • 缓存与缓冲
  • 码农张的Bug人生 - 初来乍到
  • 前端每日实战:70# 视频演示如何用纯 CSS 创作一只徘徊的果冻怪兽
  • 问题之ssh中Host key verification failed的解决
  • 译自由幺半群
  • 终端用户监控:真实用户监控还是模拟监控?
  • 组复制官方翻译九、Group Replication Technical Details
  • ​卜东波研究员:高观点下的少儿计算思维
  • # Java NIO(一)FileChannel
  • # 达梦数据库知识点
  • #!/usr/bin/python与#!/usr/bin/env python的区别
  • #NOIP 2014# day.1 T3 飞扬的小鸟 bird
  • #微信小程序:微信小程序常见的配置传值
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (zz)子曾经曰过:先有司,赦小过,举贤才
  • (附源码)计算机毕业设计SSM保险客户管理系统
  • (图)IntelliTrace Tools 跟踪云端程序
  • (转)Google的Objective-C编码规范
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .NET Core、DNX、DNU、DNVM、MVC6学习资料
  • .NET 中的轻量级线程安全
  • .net程序集学习心得
  • .sys文件乱码_python vscode输出乱码
  • [ai笔记9] openAI Sora技术文档引用文献汇总
  • [Angularjs]asp.net mvc+angularjs+web api单页应用
  • [bzoj 3124][sdoi 2013 省选] 直径
  • [bzoj 3534][Sdoi2014] 重建
  • [BZOJ] 2044: 三维导弹拦截
  • [C++]指针与结构体
  • [CareerCup] 12.3 Test Move Method in a Chess Game 测试象棋游戏中的移动方法