问题
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:
- I created the file setenv.bat inside the folder {tomcat}\bin
- 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?
回答1:
Please see detail:
- I use apache-tomcat-9.0.14-windows-x64.zip
- Sure use right java version
- Edit catalina.bat add set JAVA_OPTS=-Xms128m -Xmx1024m after setlocal
- Start Tomcat with startup.bat
- Check JVM with: start jconsole, select Tomcat, select insecure
- See XMS, XMX
If you want start Tomcat9w.exe, you need install service
回答2:
Please set in catalina.bat file: Screen shot of catalina.bat file
来源:https://stackoverflow.com/questions/54106789/how-to-increase-tomcat-heap-memory-on-windows