Search code examples
javatomcatout-of-memorytomcat8

Increasing allocated memory for tomcat didn't work using setenv.bat


I have a java web app which runs on tomcat (tomcat is installed as a windows service) and I was getting
Exception in thread "Thread-7" java.lang.OutOfMemoryError: GC overhead limit exceeded
while trying to process files using the web app. So I tried to increase allocated memory for tomcat. I checked the solutions in Increase Tomcat memory settings, Dealing with "java.lang.OutOfMemoryError: PermGen space" error and some other blogs. Here are the commands that I tried in setenv.bat file.

rem export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms256m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=1024m"
rem set "JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx8192m -XX:MaxPermSize=256m -server"
rem set JAVA_OPTS="-Xms256m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=1024m"
rem set JAVA_OPTS=%JAVA_OPTS% -Xms256m  -Xmx2048m
rem set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms256m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=1024m

I tried these command one by one. Each time I added a new command I restarted tomcat. None of these commands worked and tomcat was using its default configuration. So I changed Initial Memory Pool and Maximum Memory Pool from tomcat8w.exe -> java tab. And that worked. But I want to change the configuration using setenv.bat. How can I do that?


Solution

  • As you experienced, your tomcat service does not make use of setenv.bat at all. According to the documentation you have to invoke tomcat8 //US// to update service definitions. The settings are stored somewhere in the Windows registry.

    So the command you need might look like

    tomcat8 //US//Tomcat8 --JvmMx 2048m
    

    Alternatively it is perfectly ok to use the GUI version tomcat8was you described you have done anyway.

    In a nutshell: You cannot use setenv.bat to configure Tomcats running as service.