Out of memory error:java heap space

Hi guys,

 

 We are most struggling with “Out of memory error” in web application when reference memory is over head.

 

For example:

           

            public final class Large { 

private static final double[ ] [ ] [ ] matrix = new double [1357] [ 1687] [4]; 

                        public static final void main(String[] arg) {

                        }

            }

 

O/P:

java.lang.OutOfMemoryError: Java heap space

                        at outofmemory.Large.<clinit>(Large.java:5)

Exception in thread “main”

 

 

How to solve?

 

            Increase java heap space based on jvm which you used.

 

Set java heap size in JVM?

java -Xms64m -Xmx512m

 

where -Xms<size> specifies the initial Java heap size and -Xmx<size> the maximum Java heap size. 

 

 

Set java heap size in Tomcat?
Stop Tomcat server, set environment variable
CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,

set CATALINA_OPTS="-Xms512m -Xmx512m"  (Windows)
export CATALINA_OPTS="-Xms512m -Xmx512m"  (ksh/bash)
setenv CATALINA_OPTS "-Xms512m -Xmx512m"  (tcsh/csh)

In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. What is the difference between CATALINA_OPTS and JAVA_OPTS? The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don’t want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.
 

 

Set java heap size in JBoss?
Stop JBoss server, edit
$JBOSS_HOME/bin/run.conf, and then restart JBoss server. You can change the line with JAVA_OPTS to something like:

JAVA_OPTS="-server -Xms128m -Xmx128m"
 

 

 

 

Set java heap size in Eclipse?
You have 2 options:
1. Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse.

-vmargs
-Xms64m
-Xmx256m

2. Or, you can just run eclipse command with additional options at the very end. Anything after -vmargs will be treated as JVM options and passed directly to the JVM. JVM options specified in the command line this way will always override those in eclipse.ini. For example,

eclipse -vmargs -Xms64m -Xmx256m

 

 

Set java heap size in Weblogic?

 

Java heap size values must be specified whenever you start WebLogic Server. This can be done either from the Java command line or by modifying the default values in the sample startup scripts that are provided with the WebLogic distribution for starting WebLogic Server.

For example, when starting WebLogic Server from a Java command line, the heap size values could be specified as follows:

$ java -XX:NewSize=128m -XX:MaxNewSize=128m -XX:SurvivorRatio=8  -Xms512m -Xmx512m
-Dweblogic.Name=%SERVER_NAME% -Dbea.home=”C:\bea”
-Dweblogic.management.username=%WLS_USER%
-Dweblogic.management.password=%WLS_PW%
-Dweblogic.management.server=%ADMIN_URL%
-Dweblogic.ProductionModeEnabled=%STARTMODE%
-Djava.security.policy=”%WL_HOME%\server\lib\weblogic.policy”
 weblogic.Server

The default size for these values is measured in bytes. Append the letter `k’ or `K’ to the value to indicate kilobytes, `m’ or `M’ to indicate megabytes, and `g’ or `G’ to indicate gigabytes.

 

For more information on the heap size options

 

 

Setting the New generation heap size                        -XX:NewSize

Setting the maximum New generation heap size                   -XX:MaxNewSize

Setting New heap size ratios                                                  -XX:SurvivorRatio

Setting minimum heap size                                                     -Xms

Setting maximum heap size                                                    -Xmx

 

About these ads

10 Responses to Out of memory error:java heap space

  1. Alex says:

    I found your site on technorati and read a few of your other posts. Keep up the good work. I just added your RSS feed to my Google News Reader. Looking forward to reading more from you down the road!

  2. AlexM says:

    Your blog is interesting!

    Keep up the good work!

  3. VG says:

    Excellent. Thanks

  4. Clay says:

    The eclipse.ini changes them for eclipse itself(which may or may not need to be bigger than tomcat) but if you want to change the values that tomcat uses you will need to go to window->preferences->java-installed jre’s->edit and add them to the ‘Default VM Arguments’ box.

    I set them both and that seemed to do the trick.
    Cheers!

  5. Ash says:

    Can you please tell me how to make that configuration in UNIX server. I am struggling to increase the Java Heap space but don’t know where to find the line where i could include this configuration.
    Any help will be highly appreciated.

  6. Jagan says:

    the explanation is really good.
    Thanks alot.

  7. rajesh G says:

    nice and good

  8. mazem says:

    I am facing java heap space error while trying to delete my project resources in eclipse,My current heap size in eclipse.ini :
    xms: 40m
    xmx: 512m.

    can you please suggest the initial and maximum heap values i can set to increase the heap space.

    I have 4 GB RAM machine

  9. Anonymous says:

    According to my experience This looks mainly due to small size of permanent generation of heap.just increase size by using JVM option -XX:MaxPermSize=256m” as shown here

  10. This weblog is good. There is generally all of the appropriate information at the ideas of my fingers. Thanks and maintain up the excellent work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: