0

Tomcat is failing to start with OOM even though there is enough memory in the system and all the required memory settings are provided properly. This is not happening consistently that proves there is no issue with tomact configuration.

15-Jan-2019 20:17:31.018 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /opt/tomcat/webapps/XWY.war has finished in 66,068 ms
15-Jan-2019 20:17:31.192 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-61480]
15-Jan-2019 20:17:31.305 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [https-jsse-nio-61443]
15-Jan-2019 20:17:31.362 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 252145 ms
15-Jan-2019 21:49:18.821 SEVERE [125] org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run Unexpected death of background thread ContainerBackgroundProcessor[StandardEngine[Catalina]]
 java.lang.OutOfMemoryError: Java heap space
    at java.util.TreeMap.put(TreeMap.java:577)
    at java.util.TreeSet.add(TreeSet.java:255)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
    at java.util.TreeSet.addAll(TreeSet.java:312)
    at org.apache.catalina.webresources.Cache.backgroundProcess(Cache.java:185)
    at org.apache.catalina.webresources.StandardRoot.backgroundProcess(StandardRoot.java:601)
    at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5564)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1373)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1345)
    at java.lang.Thread.run(Thread.java:748)

Tomcat version is 8.5.8.
Java version: _JAVA_OPTIONS: -Xms1024m -Xmx3072m openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode).

  • 1
    What are your memory settings for Tomcat? They should be set in `CATALINA_OPTS` environment variable (on *nix systems, on Windows you have to configure it as described [here](https://stackoverflow.com/questions/5984540/how-do-i-increase-memory-on-tomcat-7-when-running-as-a-windows-service)). – Jozef Chocholacek Feb 06 '19 at 07:13
  • -XX:MaxPermSize=256m – PraveenJala Feb 06 '19 at 09:39
  • And the `-Xms` and `-Xmx` settings? – Jozef Chocholacek Feb 06 '19 at 09:43
  • In my tomcat i have set these values using _JAVA_OPTIONS environment variable and the value is -Xms1024m -Xmx3072m. – PraveenJala Feb 06 '19 at 09:48
  • Hmm... `-Xms1024m -Xmx3072m` should be pretty enough. So we will need more information to be able to help you: the Tomcat version, the Java version, is it an empty Tomcat installation, or is there any custom web application deployed? – Jozef Chocholacek Feb 06 '19 at 09:53
  • Tomcat version is 8.5.8, Java version is _JAVA_OPTIONS: -Xms1024m -Xmx3072m openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode). I have deployed my web application in tomcat – PraveenJala Feb 06 '19 at 09:59
  • Please edit your question and put this additional information there. – Jozef Chocholacek Feb 06 '19 at 10:00
  • _I have deployed my web application in tomcat_ - there can be some problem (memory leak) in the webapp, especially in the initialization part, which manifests itself under some condition. Would be useful to inspect the code of the webapp. – Jozef Chocholacek Feb 06 '19 at 10:15
  • total used free shared buff/cache available Mem: 64267 52559 442 183 11265 10867 Swap: 4095 4095 0 Above is the output of "free -m" command on my system. – PraveenJala Feb 06 '19 at 10:29

1 Answers1

1

Summarizing some techniques from the comments, as well as some additional steps here. Nobody will be able to give you the final answer as to why you get an OOME, you'll need to dive into it yourself:

  • A possible typo: Make sure it's not as simple as that: You mention JAVA_OPTIONS, but it'd be JAVA_OPTS. Well, actually, it's not even that:
  • For tomcat specifically: Use CATALINA_OPTS instead of JAVA_OPTS. This only sets the memory for starting Tomcat, and requires less memory for running (for example) the shutdown process.
  • Set -Xms and -Xmx to the same value: If you plan to provide -Xmx memory eventually, you might as well make sure that Java can allocate the memory while you start the process. Otherwise you might run into unavailable OS-memory on a Sunday night at 3am.
  • Connect to your running process with jconsole or a similar tool, identify the memory pattern: Does it look like an ever-increasing memory usage? Your app might have a memory leak.
  • Run a profiler on your application to identify potential memory leaks

Oddly, I couldn't find a canonical question on stackoverflow that documents how to tackle OOME - My original intent was to suggest closing this as a duplicate.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90