How to increase Java heap space for a tomcat app

2019-01-17 10:40发布

There are lots of questions that ask this or a similar question.

They all give the command that has to be executed, what I don't understand is where do I write this command. I want to permanently increase the heap space for my tomcat apps.

I read this page http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html and it says under the Tomcat section

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, no "" around the value)
export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash, "" around the value)
setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh, "" around the value)

So I replaced the line

set CATALINA_OPTS=

with

set CATALINA_OPTS=-Xms512m -Xmx512m

But I still get the error.

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.OutOfMemoryError: Java heap space java.lang.reflect.Array.multiNewArray(Native Method) java.lang.reflect.Array.newInstance(Array.java:90) nom.tam.util.ArrayFuncs.newInstance(ArrayFuncs.java:1028) nom.tam.fits.ImageData.read(ImageData.java:259) nom.tam.fits.Fits.readHDU(Fits.java:573) controller.UploadServlet.retreiveFITSFileFields(UploadServlet.java:206) controller.ScanServerFiles.doPost(ScanServerFiles.java:39) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

8条回答
ゆ 、 Hurt°
2楼-- · 2019-01-17 11:14

you can set this in catalina.sh as CATALINA_OPTS=-Xms512m -Xmx512m

Open your tomcat-dir/bin/catalina.sh file and add following line anywhere -

CATALINA_OPTS="$CATALINA_OPTS -Xms1024m -Xmx3024m"

and restart your tomcat

查看更多
淡お忘
3楼-- · 2019-01-17 11:20

First of all you cannot change the memory settings only for a tomcat application but rather for all tomcat instance.

If you are running tomcat from console (using startup.bat) you'll need to edit catalina.bat and play around with CATALINA_OPTS. For example:

set CATALINA_OPTS=-Xms512m -Xmx512m

Restarting tomcat will apply the new settings.

If you are still getting OutOfMemoryError you need to know how much memory does your application need at that particular moment (nom.tam.util.ArrayFuncs...). You'll either have to optimize the application or simply increase the memory provided to tomcat.

查看更多
登录 后发表回答