Error: Out of memory error - Tuning Java Memory

2010-04-22
This error can manifest itself in a multitude of ways, the most common being an error stating:
Servlet.service() for servlet LowayTransactionController threw exception java.lang.OutOfMemoryError

The problem with Java memory is that it is fixed, i.e. Java will not automatically use free memory unless explicityly told to do so. The default maximum memory size for most JVMs is 64 megabytes maxiumum, and it is not much if multiple users are running multi-megabyte analyses in QueueMetrics.

To tell Tomcat to use more memory than the standard pool, you have to set an environment variable before starting it up:
JAVA_OPTS="-Xms256M -Xmx512M"
export JAVA_OPTS

This tells Java to start by using 256 megabytes and expand the memory pool as needed up to 512 megabytes. Please note that Java will not return memory back to the system memory pool, so the only way to reclaim memory is by restarting Tomcat (you could restart it nightly with a script). You should also set this in the /etc/init.d/queuemetrics startup file, so that it's set system-wide when QueueMetrics starts.

A real-life example for a larger call-center using Sun JDK 1.6 may be the following set:
JAVA_OPTS="-server -Xms3072M -Xmx3072M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing"
export JAVA_OPTS

In any case, if you experience this problem, you should be reading the "Tuning QueueMetrics memory settings" section of QueueMetrics Advanced Configuration manual, that details how to tune and - most important - monitor a running JVM instance.

See http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html for more information on Java memory setting and monitoring.

See also:
  • If the error you get is actually "OutOfMemory: Unable to create new native thread", see this FAQ entry.
  • If the error you get is actually "java.lang.OutOfMemoryError: PermGen space", then you have to set the maximum PermGen size as detailed in the Advanced Configuration manual.