错误解决java.lang.OutOfMemoryError: GC overhead limit exceeded

举报
AlbertYang 发表于 2021/02/03 02:28:58 2021/02/03
【摘要】 今天做一个秒杀项目的时候,遇到了下面的错误: java.lang.OutOfMemoryError: GC overhead limit exceeded 三月 23, 2019 9:08:47 上午 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet [...

今天做一个秒杀项目的时候,遇到了下面的错误:


  
  1. java.lang.OutOfMemoryError: GC overhead limit exceeded
  2. 三月 23, 2019 9:08:47 上午 org.apache.catalina.core.StandardWrapperValve invoke
  3. 严重: Servlet.service() for servlet [spring] in context with path [/YF_MS_WEB] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
  4. java.lang.OutOfMemoryError: GC overhead limit exceeded
  5. 三月 23, 2019 9:08:53 上午 org.apache.catalina.core.StandardWrapperValve invoke
  6. 严重: Servlet.service() for servlet [spring] in context with path [/YF_MS_WEB] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
  7. java.lang.OutOfMemoryError: GC overhead limit exceeded
  8. 三月 23, 2019 9:08:59 上午 org.apache.catalina.core.StandardWrapperValve invoke
  9. 严重: Servlet.service() for servlet [spring] in context with path [/YF_MS_WEB] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
  10. java.lang.OutOfMemoryError: GC overhead limit exceeded
  11. 三月 23, 2019 9:09:08 上午 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor doRun
  12. 严重:
  13. java.lang.OutOfMemoryError: GC overhead limit exceeded
  14. 三月 23, 2019 9:09:11 上午 org.apache.tomcat.util.net.NioEndpoint$Poller run
  15. 严重:
  16. java.lang.OutOfMemoryError: GC overhead limit exceeded
  17. 三月 23, 2019 9:09:43 上午 org.apache.catalina.core.StandardWrapperValve invoke
  18. 严重: Servlet.service() for servlet [spring] in context with path [/YF_MS_WEB] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
  19. java.lang.OutOfMemoryError: GC overhead limit exceeded
  20. 三月 23, 2019 9:11:28 上午 org.apache.catalina.core.StandardWrapperValve invoke
  21. 严重: Servlet.service() for servlet [spring] in context with path [/YF_MS_WEB] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
  22. java.lang.OutOfMemoryError: GC overhead limit exceeded

 GC overhead limt exceed检查是Hotspot VM 1.6定义的一个策略,通过统计GC时间来预测是否要OOM了,提前抛出异常,防止OOM发生。Sun 官方对此的定义是:“并行/并发回收器在GC回收时间过长时会抛出OutOfMemroyError。过长的定义是,超过98%的时间用来做GC并且回收了不到2%的堆内存。用来避免内存过小造成应用不能正常工作。“

一般是应用程序在有限的内存上创建了大量的临时对象或者弱引用对象,从而导致该异常。虽然加大内存可以暂时解决这个问题,但是还是强烈建议去优化代码,后者更加有效。

解决方法:

1.你可以关闭JVM这个默认的策略:

java -XX:-UseGCOverheadLimit JavaApp
 

2.加大Heap Size:

java -Xmx512m JavaApp
 

 

注意:在修改Tomcat的catalina.bat(*.sh)中的内容时,网上有很多都是说直接修改JAVA_OPTS,按照Apache官方的说法是:
Note: Do not use JAVA_OPTS to specify memory limits. You do not need much memory for a small process that is used to stop Tomcat. Those settings belong to CATALINA_OPTS.(注意:不要使用JAVA_OPTS指定内存限制。对于用于停止Tomcat的小进程,不需要太多内存。这些设置属于CATALINA_OPTS。)

 

 

 

 

 

 

 

 

 

 

 

 

文章来源: albertyang.blog.csdn.net,作者:Albert Yang,版权归原作者所有,如需转载,请联系作者。

原文链接:albertyang.blog.csdn.net/article/details/88756167

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。