Configure tomcat memory usage

By default, the memory size allocated for tomcat is not enough to handle heavy applications which require high memory usage, several OutOfMemoryError exceptions will be thrown if you keep the default tomcat configuration. In order to set the appropriate heap size and perm gen size, tomcat requires a file named as in unix environments and setenv.bat in windows. This file is not included in the tomcat package or installation, and it is manually created under the bin directory in case the administrator needs to tune the default tomcat memory configuration.

1. setenv script

Following is the process for creating setenv script in both windows and unix machines:


Create a new script named as setenv.bat under TOMCAT_HOME/bin folder holding the following content:

P.S: If tomcat is installed as a windows service, you can also set the memory configuration through running Tomcat8w.exe under bin folder as the following:

  1. Run Tomcat8w.exe under bin folder.
  2. Set the arguments inside Java tab.


Create a new script named as under TOMCAT_HOME/bin directory holding the following content:

After creating the script, tomcat needs to be restarted for the changes to take effect.

2. setenv arguments

-Xms: This the initial java heap size.

-Xmx: This is the maximum java heap size.

The heap is the memory space which holds all the objects created by your application, it is the memory space allocated for your application, normally an application wouldn’t require more than maximum 2 GB of memory. In case of low heap space, OutOfMemoryError: java heap space” exception is thrown.

-XX:PermSize: This is the initial perm gen size.

-XX: MaxPermSize: This is the maximum perm gen size.

The perm gen size is the space where your code base is stored inside the memory , the bigger your code base is, the more perm gen space is required, normally application wouldn’t require more than maximum 1 GB of Perm gen space. In case of low perm gen space, OutOfMemoryError: PermGen” exception is thrown.



Founder of, I have a passion in software engineering and everything related to java environment.

You may also like...

Leave a Reply

Be the First to Comment!