java out of memory error-heap space

55,439

Solution 1

Finally i found the solution for the issue

in Catalina.bat file you can find some text like below

set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=

under that you need to put the

set CATALINA_OPTS=-Xms512m -Xmx512m

Heap size is larger than your computer's physical memory. For example,

java -Xmx2g BigApp Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.

The fix is to make it lower than the physical memory: java -Xmx1g BigApp

Solution 2

Try to set PermSizeand MaxPermSize values and that should be set at tomcat startup in Catalina.bat and then stop and start using this script.

  set CATALINA_OPTS=-server -Xms1024m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m

http://javahowto.blogspot.co.uk/2006/06/6-common-errors-in-setting-java-heap.html

Solution 3

I know I am totally late on this reply but in case it would be helpful to anybody runs into the same situation I think it worth to put a note here. I am referring to tomcat 9 so you might need to check how things mentioned here are relevant to your version:

In %CATALINA_HOME%/bin/catalina.bat, it clearly stated that:

rem   WHEN RUNNING TOMCAT AS A WINDOWS SERVICE:
rem   Note that the environment variables that affect the behavior of this
rem   script will have no effect at all on Windows Services. As such, any
rem   local customizations made in a CATALINA_BASE/bin/setenv.bat script
rem   will also have no effect on Tomcat when launched as a Windows Service.
rem   The configuration that controls Windows Services is stored in the Windows
rem   Registry, and is most conveniently maintained using the "tomcatXw.exe"
rem   maintenance utility, where "X" is the major version of Tomcat you are
rem   running.

If you check your %CATALINA_HOME%/bin folder, you could find a file named like "tomcat9w.exe". Double click on it and you could see this screen shot where you can set your Xms and Xmx parameters for it to save into registry for you

Hope this helps

Share:
55,439
Sathish
Author by

Sathish

Updated on May 30, 2020

Comments

  • Sathish
    Sathish almost 4 years

    I'm developing web application in jsp/servlet,i had an issue with netbeans and Java. My program needs large data process. So I used -Xmx512m to increase the maximum heap size via

    Tools -> Servers -> on the Platform tab there is a VM option below Java Platform. Then it works fine..

    Now my issue is i'm building the WAR file, directly deployed and run in my another machine Tomcat for demo, here i'm facing the same issue java out of memory error-heap space i also tried with

    environment variable set CATALINA_OPTS=-Xms512m -Xmx512m

    this also didn't help me

    how to resolve this issue?, Please point me to the right direction

  • amicngh
    amicngh over 11 years
    @Sathish which env are you using ? Window or Unix ?
  • Sathish
    Sathish over 11 years
    in Catalina.bat which line i need to add that
  • Sathish
    Sathish over 11 years
    @duffymo did you see the Catalina.bat file there are many line are there .. thats y i asked
  • amicngh
    amicngh over 11 years
    Where you have set CATALINA_OPTS= . you have to update this line.
  • duffymo
    duffymo over 11 years
    @Sathish - yes, but they don't all set CATALINA_OPTS.
  • Sathish
    Sathish over 11 years
    Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine. after that line update im not able to start the tomcat getting this error
  • Sathish
    Sathish over 11 years
    no there is no set CATALINA_OPTS line. there is the line <rem CATALINA_OPTS (Optional) Java runtime options used when the "start",>
  • amicngh
    amicngh over 11 years
    which Tomcat version are you using ?
  • amicngh
    amicngh over 11 years
    If you have JAVA_OPTS in that file you can set these here also , they will work
  • Sathish
    Sathish over 11 years
    i will try and let you know @amicngh
  • Sathish
    Sathish over 11 years
    after setting the JAVA_OPTS also the isssue remins the same Exception in thread "http-bio-7070-exec-2" java.lang.OutOfMemoryError: Java heap space