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)
LabKey recommends that the Tomcat web application be configured to have a maximum Java Heap size of at least 2GB for a test server, and at least 4GB for a production server.
There is a mechanism to do it without modifying any files that are in the distribution. You can create a separate file %CATALINA_HOME%\bin\setenv.bat
or $CATALINA_HOME/bin/setenv.sh
and put your environment variables there. Further, the memory settings apply to the JVM, not Tomcat, so I'd set the JAVA_OPTS
variable instead:
set JAVA_OPTS=-Xmx512m
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With