1

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?

Mahmud Mridul
  • 95
  • 1
  • 9
  • You didn't actually try them with the `rem` did you? `rem` is ALWAYS ignored; that's its purpose. `export` would not be valid CMD syntax; it is used for (most) Unix shells, not CMD. Your second line but with `rem` deleted is good syntax, but whether those numbers are right for your case is up to you. The `-server` probably isn't needed, but should do no harm. – dave_thompson_085 Aug 19 '22 at 07:07
  • No I didn't had rem when I was actually using those commands. – Mahmud Mridul Aug 19 '22 at 08:36

1 Answers1

1

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.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • This is working alright. I'm not getting OutofMemory exception But now when I checked tomcat8w.exe -> java -> Initial Memory Pool is 128 MB But Maximum Memory Pool is empty. Why is that? – Mahmud Mridul Aug 19 '22 at 09:46
  • I do not use Tomcat on Windows at all, so I guess I cannot tell what is wrong on your system. It might be limited to your system, or it might a bug. – Queeg Aug 19 '22 at 09:53
  • If your maximum listed is blank, then the JVM will determine what the maximum heap size will be based on whatever rules it uses. I would recommend setting that to a specific value and, usually, setting `-Xmx` to the same as `-Xms`. – Christopher Schultz Aug 21 '22 at 18:13