Accessibility

TechNote (Archived)

java.lang.OutOfMemoryError

Issue


If your servlets or JSP pages have any problems and you see"java.lang.OutOfMemoryError" in your log files or in a stack trace generated by the Java Virtual Machine (JVM), then you probably need to increase the JVM's maximum heap size.

Each instance of a Java Virtual Machine uses an allocation of memory for all objects, shared among all its threads, called theheap. As the Java Virtual Machine Specification says, "The heap is the runtime data area from which memory for all class instances and arrays is allocated."

The default size and some of the features of the heap's behavior are implementation dependent, but most (if not all) implementations allow you to modify the heap's minimum and maximum size, and most provide a default value for these settings.

Sun's Windows and Solaris 1.1 JVMs have a default maximum heap size of 16 MB. This is a very modest figure for most server-side Java applications. The default minimum heap size is 1 MB.

Sun's Windows and Solaris 1.2 and 1.3 JVMs have a default maximum heap size of 64 MB (and a default minimum heap size of 1 MB). This is a more reasonable figure, but we find that most enterprise level, server-side Java applications require a much higher setting. What setting you choose should be determined by testing and trial and error. It is highly application and load dependent. A good starter article that gives some pointers on how to estimate optimal heap settings is here, at IBM's Java site:"Heap of trouble" with the wrong heap size.

The default heap size for a 1.1.8 JVM from IBM is one-half the total physical memory size.

You should not try to catch OutOfMemoryErrors in your application. They are not generally predictable. And when they do happen, there's nothing to be done to recover, because by then the JVM is out of memory and the garbage collector is unable to free any memory for further work.

Here is the requirement for the OutOfMemoryError from the Java Virtual Machine Specification:

"If a computation requires more heap than can be made available by the automatic storage management system, the Java virtual machine throws an OutOfMemoryError." --Section 3.5.3, Heap

Solution


To increase the maximum heap size in JRun 2.3.3, edit the java.args property in jrun/jsm-default/properties/jsm.properties to look something like this for a 1.1 JDK:

java.args=-mx64m

and this for a 1.2 JDK:

java.args=-Xmx128m

Here's an example of a Java 1.2-specific java.args property setting, with min and max memory settings specified, along with some other settings, just so you can see how to add more arguments to the same property in jsm.properties:

java.args=-Xms64m -Xmx128m -Xrs -Djava.compiler=NONE

Please consult the documentation for your specific JDK for the exact syntax and the default values.

To increase the maximum heap size in JRun 3.0, use the JRun Management Console and select JRun Default Server >> Java Settings >> Java Arguments. Enter the desired argument in the input field. Select update and then restart the JRun Default Server.

Note 1: The default unit for the memory settings is in bytes, so you must add a "k" or an "m" to specify that the number is to be interpreted as kilobytes or megabytes.

Note 2: Using incorrect syntax for specifying these settings can prevent your JVM from starting. If you change these and JRun then fails when you try to restart, double check your typing in the options.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_17470
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox
Database:DB2
Informix
MySQL
Oracle
SQL Server
Sybase
MS Access

Products Affected: