Apache Tomcat

How to Solve Apache Tomcat Out of Memory Errors

Out of Memory Errors (OOME) are common in Apache Tomcat, with bugs in the underlying application being their primary cause. In some cases, the Apache Tomcat may be unable to handle high traffic.

Although Apache Tomcat 7 and updated versions have addressed and implemented fixes for the Out of Memory Errors, you may still encounter them.

This guide will discuss various measures you can implement to reduce the chances of Apache Tomcat Out of Memory Errors.

What Is an Out of Memory Error?

The Out of Memory Error means that an Apache Tomcat instance has used up all the allocated memory in the heap, causing the application to crash.

It is nearly impossible to give a specific reason why Out of Memory occurs in Apache Tomcat. However, most of them result from the applications running on the server.

Causes of Out of Memory Errors include:

  1. Heap size is too small
  2. Out of File descriptors
  3. Highly recursive code
  4. Loading large files to memory
  5. Higher threads than allowed by the host OS. 

How to Solve Apache Tomcat OOME

The simplest and most common way to solve Out of Memory Errors is to increase the Java Heap size.

On Windows, open the start menu and search for “Configure Tomcat.

Next, navigate to the Java tab and set the values for Initial Memory Pool and Maximum memory pool.

An initial memory pool of 1024 MB and a maximum of 2048 MB should suffice. Feel free to adjust per your requirements.

Click on Apply and restart the Apache Tomcat service.

If you are on Linux, open the terminal and set the Java heap size as shown in the command below:

set "JAVA_OPTS=-Xms1024m -Xmx2048m -XX:MetaspaceSize=1024M -XX:MaxMetaspaceSize=2048m"

The values specified in the previous command are in MB.

Conclusion

This quick guide discussed a simple method to solve Apache Tomcat Out of Memory Errors by increasing the Java heap size and the causes of Out of Memory Errors. I hope this article can assist you in solving Apache Tomcat Out of Memory Errors. Thank you for reading this article, and check out our other articles.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list