How to Resolve the Issue java.lang.OutOfMemoryError: Java Heap Space

| | 1 min read

We are running 3 instances of ODK and 2 more Java applications on a single server. If we try to load all these applications simultaneously, some will not load and some will be slow. When we check tomcat's log file, Catalina. out, it says, java. lang.OutOfMemoryError: Java heap space. The cause of this is explained below,

Normally java applications are allowed to use only limited memory and java memory is separated into two different regions. These regions are called Heap space and Permgen (for Permanent Generation). The size of those regions is set during the Java Virtual Machine (JVM) launch and can be customized by specifying JVM parameters -Xmx and -XX: MaxPermSize. The java. lang.OutOfMemoryError: Java heap space error occurs when it attempts to add more data into the heap space area, but there is not enough room for it.

The solution to fix this problem is to increase the heap space(Default value maybe 128 MB). We can customize the heap space by specifying the JVM parameters -Xmx and -XX: MaxPermSize.

To achieve this, please do the following,

  • Edit the catalina.sh file loacted in the bin directory of tomcat(/usr/share/tomcat7/bin).
  • We can increase the maximum Java heap size to 512 MB, by inserting the following lines: JAVA_OPTS="-Xmx512000000 " export JAVA_OPTS

Hope this helps! Please feel free to get in touch with us for further queries.