| Java JSP ORACLE Hibernate Servlet Struts Spring MySQL Java Script Post New Topic | |
| Category | Java |
| Asked By : | satya Asked Date : May 19 2008 |
| Brief Desc: | java.lang.OutOfMemoryError: Java heap space |
| Details: | java.lang.OutOfMemoryError: Java heap space
|
| Replied By: | Nick Replied Date : May 19 2008 |
| Answer: | Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size. Here are some common mistakes I have seen when using them:
Missing m, M, g or G at the end (they are case insensitive). For example, java -Xmx128 BigAppjava.lang.OutOfMemoryError: Java heap space The correct command should be: java -Xmx128m BigApp. To be precise, -Xmx128 is a valid setting for very small apps, like HelloWorld. But in real life, I guess you really mean -Xmx128m Extra space in JVM options, or incorrectly use =. For example, java -Xmx 128m BigAppInvalid maximum heap size: -XmxCould not create the Java virtual machine.java -Xmx=512m HelloWorldInvalid maximum heap size: -Xmx=512mCould not create the Java virtual machine. The correct command should be java -Xmx128m BigApp, with no whitespace nor =. -X options are different than -Dkey=value system properties, where = is used. Only setting -Xms JVM option and its value is greater than the default maximum heap size, which is 64m. The default minimum heap size seems to be 0. For example, java -Xms128m BigAppError occurred during initialization of VMIncompatible initial and maximum heap sizes specified The correct command should be java -Xms128m -Xmx128m BigApp. It's a good idea to set the minimum and maximum heap size to the same value. In any case, don't let the minimum heap size exceed the maximum heap size. Heap size is larger than your computer's physical memory. For example, java -Xmx2g BigAppError occurred during initialization of VMCould not reserve enough space for object heapCould not create the Java virtual machine. The fix is to make it lower than the physical memory: java -Xmx1g BigApp Incorrectly use mb as the unit, where m or M should be used instead. java -Xms256mb -Xmx256mb BigAppInvalid initial heap size: -Xms256mbCould not create the Java virtual machine. The heap size is larger than JVM thinks you would ever need. For example, java -Xmx256g BigAppInvalid maximum heap size: -Xmx256gThe specified size exceeds the maximum representable size.Could not create the Java virtual machine. The fix is to lower it to a reasonable value: java -Xmx256m BigApp The value is not expressed in whole number. For example, java -Xmx0.9g BigAppInvalid maximum heap size: -Xmx0.9gCould not create the Java virtual machine. The correct command should be java -Xmx928m BigApp |
| Replied By: | das Replied Date : May 19 2008 |
| Answer: | How to 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. How to 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" How to 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 How to set java heap size in NetBeans? Exit NetBeans, edit the file netbeans-install/etc/netbeans.conf. For example, netbeans_default_options="-J-Xms512m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Xverify:none How to set java heap size in Apache Ant? Set environment variable ANT_OPTS. Look at the file $ANT_HOME/bin/ant or %ANT_HOME%\bin\ant.bat, for how this variable is used by Ant runtime. set ANT_OPTS="-Xms512m -Xmx512m" (Windows)export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh) |
| Replied By: | nick Replied Date : May 19 2008 |
| Answer: | How to set java heap size in jEdit?
jEdit is a java application, and basically you need to set minimum/maximum heap size JVM options when you run java command. jEdit by default runs with a default maximum heap size 64m. When you work on large files, you are likely to get these errors: java.lang.OutOfMemoryError: Java heap spaceat java.lang.String.concat(String.java:2001)at org.gjt.sp.jedit.buffer.UndoManager.contentInserted(UndoManager.java:160)at org.gjt.sp.jedit.Buffer.insert(Buffer.java:1139)at org.gjt.sp.jedit.textarea.JEditTextArea.setSelectedText(JEditTextArea.java:2052)at org.gjt.sp.jedit.textarea.JEditTextArea.setSelectedText(JEditTextArea.java:2028)at org.gjt.sp.jedit.Registers.paste(Registers.java:263) How to fix it? If you click a desktop icon, or Start menu item to start jEdit: right-click the icon or menu item, view its property, and you can see its target is something like: C:\jdk6\bin\javaw.exe -jar "C:\jedit\jedit.jar" You can change that line to: C:\jdk6\bin\javaw.exe -Xmx128m -Xms128m -jar "C:\jedit\jedit.jar" If you run a script to start jEdit: just add these JVM options to the java line inside the script file: java -Xmx128m -Xms128m -jar jedit.jar If you start jEdit by running java command: just add these JVM options to your java command: java -Xmx128m -Xms128m -jar jedit.jar Note that when you run java with -jar option, anything after -jar jar-file will be treated as application arguments. So you should always put JVM options before -jar. Otherwise, you will get error: C:\jedit>java -jar jedit.jar -Xmx128mUnknown option: -Xmx128mUsage: jedit [] [] How to set java heap size in JavaEE SDK/J2EE SDK/Glassfish/Sun Java System Application Server? Stop the application server, edit $GLASSFISH_HOME/domains/domain1/config/domain.xml, search for XML element name java-config and jvm-options. For example, <java-config suffix="..."><jvm-options>-Xmx512m</jvm-options><jvm-options>-XX:NewRatio=2</jvm-options><jvm-options>-XX:MaxPermSize=128m</jvm-options>...</java-config> You can also change these settings in the web-based admin console, typically at http://localhost:4848/, or https://localhost:4848/. Go to Application Server near the top of the left panel, and then on the right panel, click JVM Settings -> JVM Options, and you will see a list of existing JVM options. You can add new ones and modify existing ones there. Yet another option is to use its Command Line Interface (CLI) tool command, such as: ./asadmin help create-jvm-options./asadmin help delete-jvm-options In tomcat the heap size can be passed to the java here. "$_RUNJAVA" -Xmx512M $JAVA_OPTS $CATALINA_OPTS If you open your catalina.bat (for Win) there will be a line like set JAVA_OPTS=(some option here ) Just append -Xms512m -Xmx512m to it and restart tomcat . That should increase the heap size for u |
| Replied By: | satya Replied Date : Jun 5 2008 |
| Answer: | how to increase heap size :
step 1. open D:\jakarta-tomcat-5.0.28\bin\catalina.bat step 2. add -Xmx512M before %JAVA_OPTS% where you find %JAVA_OPTS% .. before this just put -Xmx512M like this %_EXECJAVA% -Xmx512M %JAVA_OPTS% or these are the lines i have changed in my machine this is for 512 MB Setting. All the line are there already ..just replace ------------------------------------------------- rem Execute Java with the applicable properties if not "%JPDA%" == "" goto doJpda if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity %_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% goto end :doSecurity %_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% goto end :doJpda if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda %_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% -Xdebug -Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% goto end :doSecurityJpda %_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% -Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% goto end :end |
| Replied By: | ds Replied Date : Jun 18 2008 |
| Answer: | http://www.jbsolutions.net.in/out_of_memory_issue.html
|
| Replied By: | VS Replied Date : Jun 26 2008 |
| Answer: | get more details on
http://www.jbsolutions.net.in/out_of_memory_issue.html |
| Replied By: | rag Replied Date : Jul 1 2008 |
| Answer: | very good one at http://techforum360.com/forum/viewthread?thread=17
|
| Replied By: | BatsWon Replied Date : Aug 25 2008 |
| Answer: | Thank you very much!!!!!!! Satya. It worked for me
|
| Replied By: | Irina Replied Date : Sep 5 2008 |
| Answer: | I have following line in catalina.sh
CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS -Xms1024m -Xmx1024m" When I go to Server status it has JVM Free memory: 5.91 MB Total memory: 14.65 MB Max memory: 63.81 MB I am trying to create 10 MB file and getting error from the java bean SEVERE: Servlet.service() for servlet jsp threw exception java.lang.OutOfMemoryError: Java heap space I don't know what is wrong. Irina. |
| Replied By: | Jing Replied Date : Oct 22 2008 |
| Answer: | Thank you, Satya, it works for me too. You have helped us resolve this long term issue.
You are brilliant!!!!!!!!!! Jing |
| Replied By: | Bharti Replied Date : Mar 26 2009 |
| Answer: | thanks Satya! Your Solution was of great Help!!It Fixed my issues.
|
| Replied By: | varshna Replied Date : Apr 15 2009 |
| Answer: | I am using tomcat and also have to change the heap size...there where different sites that explaine it but there is one thing i don't get done:
this is the site: http://blog.paulgu.com/2008/07/19/6-common-errors-in-setting-java-heap-size/ How to 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. How must i do this: set environment variable CATALINA_OPTS?? |
| Replied By: | Anoop Replied Date : May 12 2009 |
| Answer: | How to set heap space in Tomcat5.5.27???
|
| Replied By: | Anoop Replied Date : May 12 2009 |
| Answer: | How to set heap space in Tomcat5.5.27???
|
| Replied By: | rajesh Replied Date : Aug 31 2009 |
| Answer: | to set heap size in tomcat we can edit starttomcat - http://hiox.org/index.php?id=443
|
| Replied By: | Raja Replied Date : Nov 17 2009 |
| Answer: | Hi guys am doing Performance testing in jmeter wen i give more than 60 users in the thread jmeter gets crash and shows the error "Java Heap Space" can any one know the solution for this?
|
| Replied By: | Randy Amos Replied Date : Aug 24 2010 |
| Answer: | For those of us running Tomcat(5.5.23 is my version) in Windows (Server 2003 for me) check this link out which shows where to make these changes in the properties settings.
http://cephas.net/blog/2005/03/16/modifying-memory-allocation-on-tomcat-5x-on-windows/ |
| Replied By: | lavanya Replied Date : Aug 26 2010 |
| Answer: | hi,
Iam getting similar error in weblogic. i set it like this, -ms512m -mx512m -XX:PermSize=256m -XX:MaxPermSize=256m but still no use. can you please advice |
| Replied By: | raj Replied Date : Oct 22 2010 |
| Answer: | I dont habve java installed on my PC. While I was uploading some doc, I got error:
HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception root cause java.lang.OutOfMemoryError: Java heap space note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs. -------------------------------------------------------------------------------- Apache Tomcat/6.0.18 |
| Replied By: | 11 Replied Date : Oct 22 2010 |
| Answer: | 1
|
| Replied By: | Prasanth Replied Date : Sep 2 2011 |
| Answer: | Hello,
I am facing the issue with memory heap size error. I have increased the memory to 3 GB. java -Xms3072m -Xmx3072m Still I am having the same issue. Please suggest is there any way to resolve the issue? |
| Replied By: | Anonymous Replied Date : Oct 3 2011 |
| Answer: | here is another good link on solving OutOfMemoryError : http://javarevisited.blogspot.com/2011/09/javalangoutofmemoryerror-permgen-space.html
|
| Replied By: | Anonymous Replied Date : Oct 3 2011 |
| Answer: | <a href="http://javarevisited.blogspot.com/2011/09/javalangoutofmemoryerror-permgen-space.html">java.lang.OutOfMemoryError: Java heap space </a>
|
| Replied By: | SHREYA Replied Date : May 11 2012 |
| Answer: | PLS TELL ME HOW TO WORK TOMCAT ..BECAUSE I HAVE JAVA
BUT I CAN'T WORK ON JSP AND TOMCAT...WHICH TYPE OF WORKIG ON THIS S/W..PLS EXPLAINE |
| Replied By: | Munivelu Replied Date : May 30 2012 |
| Answer: | Tomcat is one of the popular webserver among all the servers. Server receives the request given by user which is implemented in jsp or whatever , and executes in server, finally server will response the result to the user. jsp is a serverside program so, we need server.
|
| Replied By: | ritesh dubey Replied Date : May 15 2013 |
| Answer: | Reply to miss shreya,
for tomcat you sholud know jsp,jsp is like html with few more tags.its really easy. you can google it also . for any queries , u can contact ritesh100@gmail.com conatct :09769346099 |