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

Vesselin picture Vesselin · Jan 19, 2016 · Viewed 20.8k times · Source

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)

Answer

Scott Izu picture Scott Izu · Jul 13, 2017

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/