Configuring Tomcat’s Java Heap Size

In this tutorial you will use a GUI utility that ships with Tomcat to configure Java options. This tutorial uses Tomcat6, but the techniques should be the same for newer releases.

Tomcat running as a Windows Service

Locate and copy the location of tomcat6w.exe (if using Tomcat7, this will be named tomcat7w)

  1. Open and navigate through directory windows as shown in the screen shot below.
  2. Right-click the directory path bar and click Copy address as text.
  3. The clipboard should contain a string such as C:\Program Files\jasperreports-server-4.5.1\apache-tomcat\bin.


Open a command line window with Administrator privileges

  1. From the Start menu, enter “command” in the Search programs and files box.
  2. From the list of files, right-click “Command Prompt” and choose Run as administrator.


Run the tomcat6w application

 

  1. In the command box, type “cd” (to change directories) then right-click to paste the path to the Tomcat bin directory. Press return.
  2. Now in the Tomcat bin directory, type “tomcat6w //ES//jasperreportsTomcat” and press return.
  3. Click the Java tab. Edit the values in the Java Options box. The following settings allocate 2 GB memory to the start Java heap, 6 GB for the maximum heap size, 128 MB for the permgen space and 256 MB for the maximum permgen size.


    The following settings allocate 2 GB memory to the start Java heap, 6 GB for the maximum heap size, 128 MB for the permgen space and 256 MB for the maximum permgen size.

    Xmx2048M Xmx6144M   other settings, e.g. thread stack, directory license location etc   XX:PermSize=128m XX:MaxPermSize=256m

  4. Click OK to close the applet.
  5. Restart the Tomcat service (from the Start menu, you can navigate to JasperReports Server > Start or Stop Services).

Tomcat running in stand alone mode as an exe

When you get Java Heap memory related error java.lang.OutOfMemoryError. It is  basically is  JVM heap size problem.  So for increasing the JVM Heap Size of Tomcat in Windows two way is there.

Method 1:
You have to create environment variable with name JAVA_OPTS and value -Xms256m -Xmx512m of course you can change the 256 and the 512 to whatever values you want. Here is the step by step process.

1. Right click on  computer icon and click on properties.

2. Click on  advanced system setting link.

3. Select the advanced tab.Here is the screen shot.

4. Click on Environment Variables button.

5. On system variables part :
– Click on new button.
– In the variable name, type : JAVA_OPTS
– In the variable value, type: -Xms256m -Xmx512m
– Click ok -> ok ->ok.
Now you have the environment variable JAVA_OPTS set to -Xms256m -Xmx512m.

Here  -Xms256m (minimum of 256 MB)
          -Xms512m (maximum of 512 MB)

Method 2:

Go to catalina.bat, catalina.bat is present in bin folder of your Tomcat Directory, and set this.

set JAVA_OPTS=-Xms128m -Xmx192m

Method 3:

Create a new file setenv.bat in the bin folder and paste the following contants in it –

set JAVA_OPTS=-Xms128m -Xmx256m

One thought on “Configuring Tomcat’s Java Heap Size

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s