WebObjects 5: "java.lang.OutOfMemoryError" Exception

This document explains how to prevent a WebObjects application from running out of memory.
Symptom

A WebObjects application may stop responding ("crash" or "hang") with a "java.lang.OutOfMemoryError" exception if the application is particularly large, maintaining a large number of active sessions, or caching too many database objects.


Solution

Assuming the memory usage of the application cannot be reduced (by limiting the number of active sessions, limiting database fetches, and so forth), the exception can be prevented by allowing the Java VM to use more RAM. Unlike other application processes, Java applications are launched with an option specifying the maximum allowed RAM usage. The default maximum is 64 MB.

Use the Java command-line option -Xmx to change the maximum RAM usage. There are three places where this can be set:

Method 1: Use Project Builder.

This method only affects applications launched from within Project Builder.


Method 2: Use Project Builder.

This method affects applications launched from within Project Builder, applications launched from the command-line, and applications launched from Monitor.


Method 3: Use the Monitor (JavaMonitor) application.

This method only affects applications launched from Monitor.


About -Xmx128m

The option -Xmx128m sets the maximum RAM usage to 128 MB, but is only an example. Experiment with different values to find what gives the best performance. Setting the value too high may cause temporary slowdowns during garbage collection or disk paging. Some applications may benefit from setting the minimum RAM usage equal to the maximum. You can do this by setting the Java VM options to -Xms128m -Xmx128m.

These techniques may be used to set certain other Java VM options as well. Any option beginning with -X or -D may be specified. For more information on available arguments, see the Java runtime documentation (http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/java.html#options).

Published Date: Feb 19, 2012