How to increase Tomcat Heap memory on windows

2019-08-19 01:07发布

I read many posts on the internet and here on stackoverflow, but I'm still not able to increase Tomcat Heap Size. Probably I made an error that I can't recognize.

Following this guide I did these steps:

  1. I created the file setenv.bat inside the folder {tomcat}\bin
  2. Inside the file setenv.bat I added the string set "JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx1024m -XX:MaxPermSize=512m -server"

When I run Tomcat and then I launch my app (for instance localhost:8080/appName) and I try to know the heap informations this way:

long maxHeapSize = Runtime.getRuntime().maxMemory();        
long freeHeapSize = Runtime.getRuntime().freeMemory();  
long totalHeapSize = Runtime.getRuntime().totalMemory();    
System.out.println("Max Heap Size = " + (maxHeapSize/1024/1024)+ " MB");    
System.out.println("Free Heap Size = " + (freeHeapSize/1024/1024)+ " MB");  
System.out.println("Total Heap Size = " + (totalHeapSize/1024/1024)+ " MB");        

I get that the Max Heap Size is always 256 MB. Does anybody know what's my error?

2条回答
戒情不戒烟
2楼-- · 2019-08-19 01:34

Please see detail:

  1. I use apache-tomcat-9.0.14-windows-x64.zip
  2. Sure use right java version
  3. Edit catalina.bat add set JAVA_OPTS=-Xms128m -Xmx1024m after setlocal
  4. Start Tomcat with startup.bat
  5. Check JVM with: start jconsole, select Tomcat, select insecure
  6. See XMS, XMX

If you want start Tomcat9w.exe, you need install service

查看更多
Melony?
3楼-- · 2019-08-19 01:49

Please set in catalina.bat file: Screen shot of catalina.bat file

查看更多
登录 后发表回答