How To Change The Java Memory Settings For Tomcat

Increase Memory in Linux

 
You can set the minimum and maximum memory heap size with the JVM -Xms and -Xmx parameters, for example, setting the minimum heap size to 128 MB and the maximum heap size to 1024 MB.
  
Let's first understand what -Xms, -Xmx, -XX:PermSize and -XX:MaxPermSize are,
  1. -Xmx<size> - Set initial Java heap size.
  2. -Xmx<size> - Set maximum Java heap size.
  3. -XX:PermSize - Initial java permanent space size.
  4. -XX:MaxPermSize - Maximum java permanent space size.
To set the memory, you have a file named "setenv.sh" in your /tomcat/bin directory. If the file doesn’t exist, then you need to create the file within and set the parameters.
  1. export JAVA_OPTS = "-Xms128m –Xmx256m"   
As described above, all these settings take place in the setenv.sh. Add the lines of code mentioned below.
  1. export JAVA_OPTS = "-Xms128m -Xmx256m -XX:MaxPermSize=512m"  
  2. JAVA_OPTS = "-Xms256M –Xmx1024M"     

Increase Memory in Windows (Started Manually)

 
 To set the memory, you have a file named "setenv.bat" in your /tomcat/bin directory. If the file doesn’t exist, then you need to create the file within and set the parameters.
  1. set JAVA_OPTS = "-Xms128m –Xmx256m"   
As described above, all these settings take place in the setenv.bat. Add the code mentioned below.
  1. set JAVA_OPTS = "-Xms128m -Xmx256m -XX:MaxPermSize=512m"  
  2. JAVA_OPTS = "-Xms256M –Xmx1024M"