Tomcat 因错误 java.lang.OutOfMemoryError 崩溃:超出 GC 开销限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34882071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:30:00  来源:igfitidea点击:

Tomcat crashes with error java.lang.OutOfMemoryError: GC overhead limit exceeded

javatomcatgarbage-collectionatmosphere

提问by Vesselin

After the tomcat ran several months, I got unexpectetly the error below. We restarted the tomcat and the error do not appear now but may be will come again in the future. I saw that another users had simmilar exceptions, related with the garbage collection, but not related exactly with the NIO connector.

在tomcat运行几个月后,我出乎意料地出现了以下错误。我们重新启动了tomcat,错误现在没有出现,但将来可能会再次出现。我看到另一个用户有类似的异常,与垃圾收集相关,但与 NIO 连接器不完全相关。

Does somebody has an idea why this happens and what should be the correct fix to avoid it.

有人知道为什么会发生这种情况,以及应该采取什么正确的解决方法来避免这种情况。

Jan 15, 2016 7:46:47 AM org.apache.tomcat.util.net.NioEndpoint$SocketProcessor run
SEVERE: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
        at java.util.Collections.synchronizedSet(Collections.java:1691)
        at org.atmosphere.cpr.AtmosphereRequest$Builder.<init>(AtmosphereRequest.java:1146)
        at org.atmosphere.cpr.AtmosphereRequest.wrap(AtmosphereRequest.java:1891)
        at org.atmosphere.cpr.AtmosphereServlet.event(AtmosphereServlet.java:295)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilterEvent(ApplicationFilterChain.java:484)
        at org.apache.catalina.core.ApplicationFilterChain.doFilterEvent(ApplicationFilterChain.java:377)
        at org.apache.catalina.core.StandardWrapperValve.event(StandardWrapperValve.java:411)
        at org.apache.catalina.core.StandardContextValve.event(StandardContextValve.java:146)
        at org.apache.catalina.valves.ValveBase.event(ValveBase.java:224)
        at org.apache.catalina.core.StandardHostValve.event(StandardHostValve.java:256)
        at org.apache.catalina.valves.ValveBase.event(ValveBase.java:224)
        at org.apache.catalina.valves.ValveBase.event(ValveBase.java:224)
        at org.apache.catalina.core.StandardEngineValve.event(StandardEngineValve.java:138)
        at org.apache.catalina.connector.CoyoteAdapter.event(CoyoteAdapter.java:210)
        at org.apache.coyote.http11.Http11NioProcessor.event(Http11NioProcessor.java:124)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1690)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)

回答by Arnaud

Either your server didn't have enough memory to manage some particularly memory-consuming task, or you have a memory leak.

要么你的服务器没有足够的内存来管理一些特别消耗内存的任务,要么你有内存泄漏。

  1. For the first case, you may want to change memory settings of tomcat with -Xmxand -XmsVM arguments, see Java VM options.
  1. 对于第一种情况,您可能希望使用-Xmx-XmsVM 参数更改 tomcat 的内存设置,请参阅Java VM 选项

This topic shows a full example for Tomcat: Increase Tomcat memory settings

本主题显示了Tomcat的完整示例:增加 Tomcat 内存设置

  1. For the second case, you should create a heap dump, with jmapfor instance.
  1. 对于第二种情况,您应该heap dump使用jmap创建一个,例如。

A heap dump file represents the current heap allocation of a java process.

堆转储文件表示 Java 进程的当前堆分配。

jmap -dump:file=<file-name> <process-id>

Here, <file-name>is the file you want to create, and <process-id>is the id of the Tomcatprocess.

这里,<file-name>是你要创建的文件,<process-id>Tomcat进程的id 。

Some tools like Eclipse MAT, can open and analyze a heap dump file, tell you the number of objects by class, occupied memory by object types, memory leak suspects, and so on...

一些工具,如Eclipse MAT,可以打开并分析一个堆转储文件,告诉你按类划分的对象数量、按对象类型占用的内存、内存泄漏嫌疑人等等......

回答by Scott Izu

OPTION 1 CATALINA.BAT

选项 1 CATALINA.BAT

If you are running Tomcat from the following (Windows):

如果您从以下 (Windows) 运行 Tomcat:

catalina.bat start

Then, you should create a file setenv.batand add the following line:

然后,您应该创建一个文件setenv.bat并添加以下行:

set JAVA_OPTS="-Xms4096m -Xmx4096m"

OPTION 2 CATALINA.SH

选项 2 CATALINA.SH

If you are running Tomcat from the following (Linux):

如果您从以下 (Linux) 运行 Tomcat:

catalina.sh start

Then, you will have to do a similar thing and create setenv.sh adding something like the following:

然后,您将不得不做类似的事情并创建 setenv.sh 添加如下内容:

export JAVA_OPTS="-Xms4096m -Xmx4096m"

See also Increase Tomcat memory settings

另请参阅增加Tomcat内存设置

OPTION 3 TOMCAT SERVICE

选项 3 Tomcat 服务

If you are running Tomcat from a Windows Service that was installed using the Tomcat installer, go to the Windows command prompt and run something like this (this is for Tomcat 8 and can be found in something like C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin):

如果您从使用 Tomcat 安装程序安装的 Windows 服务运行 Tomcat,请转到 Windows 命令提示符并运行类似的内容(这是针对 Tomcat 8 的,可以在类似内容中找到C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin):

Tomcat8w.exe

Under the Javatab, you will see Initial memory pooland Maximum memory pool. Enter this into both fields:

Java选项卡下,您将看到Initial memory poolMaximum memory pool。将其输入到两个字段中:

4096

Click Applyand OK.

单击ApplyOK

From Task Manager, ServicesTab, Services, Select Apache Tomcatand press start

Task Manager, ServicesTab, Services, 选择Apache Tomcat并按start

See also Configure Tomcat as a service (no catalina.bat)and https://plavc.wordpress.com/2012/02/08/tomcat-service-on-windows/

另请参阅将Tomcat 配置为服务(无 catalina.bat)https://plavc.wordpress.com/2012/02/08/tomcat-service-on-windows/