问题
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
回答1:
Try to set PermSize
and 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
回答2:
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
回答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
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/12366989/java-out-of-memory-error-heap-space