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...

转载于:https://www.cnblogs.com/diyunpeng/archive/2011/05/23/2054500.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/422852.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Git、GitHub、GitLab】九 工作中非常重要的一些git用法

上一篇文章学习了 如何修改commit的message&#xff0c;点击链接查看&#xff1a;【Git、GitHub、GitLab】八 如何修改commit的message 注意&#xff1b;下面的‘–’ 都是两个‘-’组成 本文介绍一些在使用git中非常常用的一些命令&#xff1a; 怎么比较暂存区与HEAD所指向的…

【Git、GitHub、GitLab】十 将git仓库备份到本地

上一篇文章学习记录了工作中常用的一些git命令&#xff0c;点击链接查看&#xff1a;【Git、GitHub、GitLab】九 工作中非常重要的一些git用法 文章目录1 git的传输协议2 如何将git仓库备份到本地2.1 使用哑协议备份2.2 使用智能协议备份1 git的传输协议 哑协议与智能协议的区别…

Ibatis XML 配置文件注释引起错误及解决方案

最近在使用Ibatis组件进行一个项目开发&#xff0c;在运行时发现提示如下错误信息&#xff1a; type 异常报告 消息 描述服务器遇到一个内部错误 (), 无法完成此请求。 异常 javax.servlet.ServletException: java.lang.ExceptionInInitializerError根本原因 java.lang.Excep…

java-XML

XML不再多说&#xff0c;XML 约束也不用说了&#xff0c;这里讲讲java如何对XML操作。 java中使用XML&#xff0c;目前常用的就是Jaxp(sun)和dom4j了&#xff0c;这里先讲讲java自带的Jaxp包 JAXP 开发包是J2SE的一部分&#xff0c;它由javax.xml、org.w3c.dom 、org.xml.sax 包…

7款开源ERP系统比较

现在有许多企业将ERP项目&#xff0c;在企 业中没有实施好&#xff0c;都归咎于软件产品不好。其实&#xff0c;这只是你们的借口。若想要将ERP软件真正与企业融合一体&#xff0c;首先得考虑企业的自身情况&#xff0c;再去选择适合的 ERP软件。 如果你的企业是高速发展的中小…

【C语言进阶深度学习记录】一 数据类型的本质与变量的本质

今天学习C语言中的数据类型的本质与变量的本质 文章目录1 什么是数据类型2 变量的本质3 数据类型与变量的关系4 自定义数据类型与创建变量5 总结1 什么是数据类型 数据类型可以理解为固定内存大小的别名数据类型是创建变量的模子 如同下面的图示&#xff0c;各个数据类型是代…

我想回宋代去@@

<故乡原风景> 静夜&#xff0c;闭上眼。梦里&#xff0c;幻里……孤刃万重山&#xff0c;天高地阔。一声塞外铃鼓&#xff0c;摇坠长河落日圆&#xff0c;夕照残阳似血。乡关日暮是何处&#xff1f;仗剑独行天涯客&#xff0c;临风勒马凭高处。不识旧时飞雁&#xff0c;任…

使用第三方Markdown编辑器编辑为知笔记

前言 为知笔记默认的编辑器并没有预览功能&#xff0c;而提供的MD编辑器插件也并不是很好用&#xff0c;但为知笔记提供了可以使用第三方编辑器的功能&#xff0c;Typora编辑器是目前最优秀的Markdown编辑器之一&#xff0c;可以很好作为第三方编辑器。 Typora介绍 Typora是…

【C语言进阶深度学习记录】二 有符号与无符号

今天学习C语言中的有符号与无符号 文章目录1 计算机中的符号位1.1 有符号数的表示法1.2 无符号数的表示法1.3 signed 和 unsigned2 实验-当有符号数与无符号数进行运算3 错误的使用了unsigned4 总结1 计算机中的符号位 C语言中&#xff0c;数据类型的最高位&#xff0c;用于标…

【转载】Linux中断处理学习笔记

1&#xff0e;Linux中断的注册与释放&#xff1a; 在<linux/interrupt.h>, , 实现中断注册接口: int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *dev_name, void *dev_id); void free_…

【C语言进阶深度学习记录】三 浮点数(float) 在内存中的表示方法

相信大多数人知道整形数在内存中的分布方式&#xff0c;而且也能很容易写出其二进制的形式&#xff0c;但是对于浮点数&#xff0c;估计知道的人并不是很多今天学习在C语言中浮点数在内存中的表示方法 文章目录1 浮点数在内存中的存储方式1.1 浮点数的转换步骤1.2 浮点数的转换…

使用默认Model Binding支持集合类

Form【http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx】 Yes, my yet another post on Model Binding (previous one is here), but this one uses features presented in MVC 2. How I got to writing this blog? Wel…

windows 下cmd命令行的替换工具cmder

1 简介 与windows自带的cmd相比&#xff0c;cmder具有更加友好的界面 2 安装与配置 安装 下载&#xff1a;http://cmder.net/ 下载之后&#xff0c;解压到指定目录即可 双击 cmder.exe 运行 或 windows键 R 后输入 cmder 来打开 配置 注册到右键菜单: 在命令行揭秘额&#x…

重新设定mysql密码~,网上方法都是,这里选一个。

新开一个终端&#xff0c;对&#xff0c;就是要输入jobs后没有输出的终端。1终止MYSQL服务。sudo killall mysqld2特殊运行MYSQLmysqld_safe --skip-grant-tables &登录mysql -u root设密码mysql> use mysql;Reading table information for completion of table and col…

【C语言进阶深度学习记录】四 C语言中的类型转换

今天学习C语言中的类型转换&#xff0c;包括隐式类型转换和显示类型转换 文章目录1 C语言中的数据类型转换1.1 强制类型转换1.11 强制类型转换代码分析1.&#xff12; 隐式类型转换1.21 隐式类型转换代码分析2 总结1 C语言中的数据类型转换 C语言中&#xff0c;可以进行数据类…

【C语言进阶深度学习记录】五 C语言中变量的属性

上一篇文章学习了C语言中的类型转换&#xff0c;点击链接查看&#xff1a;【C语言进阶深度学习记录】四 C语言中的类型转换. 文章目录1 C语言的变量属性1.1 auto关键字1.2 register关键字1.3 static 关键字1.4 代码案例分析1.5 extern 关键字1.6 代码案例分析2 总结1 C语言的变…

hash编码

常用的字符串Hash函数还有ELFHash&#xff0c;APHash等等&#xff0c;都是十分简单有效的方法。这些函数使用位运算使得每一个字符都对最后的函数值产生影响。另外还有以MD5和SHA1为代表的杂凑函数&#xff0c;这些函数几乎不可能找到碰撞。 常用字符串哈希函数有 BKDRHash&…

【C语言进阶深度学习记录】六 C语言中的分支语句

文章目录1 if 语句的分析1.1 if 语句中零值比较的注意点2 switch 语句的分析3 if 与switch语句使用代码案例分析4 if语句与switch语句的互换5 总结1 if 语句的分析 if 语句根据条件选择执行语句else 不能独立存在&#xff0c;且总是与距离它最近的if匹配else 语句可以连接其他…

【C语言进阶深度学习记录】七 C语言中的循环语句

文章目录1 循环语句分析1.1 do...while循环1.2 while循环1.3 for循环1.4 三种循环语句使用对比2 break和continue的区别3 总结1 循环语句分析 C语言中的循环语句主要有for循环&#xff0c;while循环和do…while循环。 循环语句的基本工作方式&#xff1a; 通过条件表达式判断…

overload和override的区别

override&#xff08;重写&#xff09; 1、方法名、参数、返回值相同。2、子类方法不能缩小父类方法的访问权限。3、子类方法不能抛出比父类方法更多的异常(但子类方法可以不抛出异常)。4、存在于父类和子类之间。5、方法被定义为final不能被重写。overload&#xff08;重载&am…