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

2

9

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.

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)
Cutcheon answered 19/1, 2016 at 16:33 Comment(0)
S
10

OPTION 1 CATALINA.BAT

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

catalina.bat start

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

set JAVA_OPTS="-Xms4096m -Xmx4096m"

OPTION 2 CATALINA.SH

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

catalina.sh start

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

export JAVA_OPTS="-Xms4096m -Xmx4096m"

See also Increase Tomcat memory settings

OPTION 3 TOMCAT SERVICE

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):

Tomcat8w.exe

Under the Java tab, you will see Initial memory pool and Maximum memory pool. Enter this into both fields:

4096

Click Apply and OK.

From Task Manager, Services Tab, Services, Select Apache Tomcat and press start

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

Senator answered 13/7, 2017 at 1:52 Comment(2)
Hi @Scott, what if I run tomcat on Amazon ElastiC Beanstalk servers? I got same issue, I have restarted servers and it works...Vu
Hi Scott, you are such a savior. You have no idea. Thanks a lot.Marasco
P
6

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 -Xmx and -Xms VM arguments, see Java VM options .

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

  1. For the second case, you should create a heap dump, with jmap for instance.

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

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

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

Pulmonic answered 19/1, 2016 at 16:51 Comment(1)
The second point I plan to try it in order to detect the problem. About the application, it has very low load as users, activity, etc. on the server where the problem appeared. So I guess the standart memory settings should be enough.Cutcheon

© 2022 - 2024 — McMap. All rights reserved.