Sathish
Sathish

Reputation: 4713

java out of memory error-heap space

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

Upvotes: 5

Views: 61028

Answers (5)

kaiv
kaiv

Reputation: 173

Out of memory error can be result of big session-timeout number in Tomcat's web.xml. In that case many web sessions can take many system memory.

Upvotes: 0

Creambun
Creambun

Reputation: 21

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

Upvotes: 2

amicngh
amicngh

Reputation: 7899

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

Upvotes: 11

Sathish
Sathish

Reputation: 4713

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

Upvotes: 8

Manikandan Kannan
Manikandan Kannan

Reputation: 9014

I suggest you enable heap dump and analyze using IBM support Workbench (which has heap dump analyzers) and understand the problem exactly and make configurations accordingly.

Upvotes: -1

Related Questions