It’s quite common to run In memory problems when running some big Java EE application on a Tomcat server.
Some of the most commmon errors are like the following ones.

This is about a full Heap space:

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.OutOfMemoryError: Java heap space

This other is about the PermGen space that’s a memory area, where compiled classes (and JSPs) are kept, and this error might happen often if the running web application have many .java and .jsp.

MemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space

To increase the memory available to Tomcat, about heap and permgen the correct options are the following ones.

This sets the max heap available to Tomcat at 1Gb of memory:

--JvmMx 1024

This sets the max permgen available to Tomcat at 256Mb of memory:

-XX:MaxPermSize=256m

To change the Tomcat memory settings (when Tomcat is installed on Windows as system service), it’s required to use the command-line tool tomcat6. The next command changes the memory settings for the Tomcat service named Tomcat6

tomcat6 //US//Tomcat6 --JvmMx 1024 ++JvmOptions="-XX:MaxPermSize=256m"

The label //US//Tomcat6 has the meaning of Updating Server parameters for the service named Tomcat6.
Obviously this command should be executed from the directory C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin or from wherever is the bin directory of your Tomcat installation. Or to make things simple, that directoy should be added to your PATH environment variable.

It’s even possible to update memory settings from a GUI frontend, or to view what happened after running the command line tool. Running the following command:

tomcat6w //ES//Tomcat6

a window will open showing all the parameters about the windows service Tomcat6.

It’s possible to see in this image that, after running the previous command, for setting higher memory limits, in the sections Maximum memory pool and at the end of the Java Options the new memory limits are set.

Tomcat Memory Settings on Windows

Tomcat Memory Settings on Windows



8 Comments

  1. #
    Sudheer
    April 14th, 2009 at 5:25 am

    good…
    how to solve the same problem in Ubuntu..
    when am executing the same command am getting the error like ” tomcat6 command not found ” in bin directory

    Reply to this comment
    • #
      Zulutown Webmaster
      April 14th, 2009 at 5:44 am

      tomcat6.exe is for Windows.
      On ubuntu… I suggest to give you a look to catalina.sh, and set the $CATALINA_OPTS variable.
      How do you run Tomcat on your ubuntu server?

      Reply to this comment
  2. #
    shobha
    July 12th, 2009 at 3:27 am

    Thanks a ton.
    I am able to resolve memory issue now. But i am unable to run tomcat6w //ES//Tomcat6, it gives me an error message telling that an instance of ‘ Tomcat is already running’ even though i have stopped it. Any tips to resolve this too.

    Reply to this comment
  3. #
    Jaycee
    September 1st, 2009 at 8:35 am

    I’m a little confused about how the maximum values por “maximum memory pool” are afected by the windows version or sistem’s memory size…

    Reply to this comment
  4. #
    Sam
    June 4th, 2010 at 3:47 am

    Thanks a lot. You are adorable. Such a nice help.

    Reply to this comment
  5. #
    Ross Saunders
    July 1st, 2010 at 3:39 am

    This article is by far the simplest and most effective I’ve found on this topic. Good going!

    @shobha – Make sure that the Tomcat monitor is not running in the taskbar next to the clock. Double click on the monitor to see the config.

    Reply to this comment
  6. #
    EMS
    July 2nd, 2010 at 11:22 am

    Thank you Thank you. Excellent tutorial. Solved my issue.

    Reply to this comment
  7. #
    Lakshmi
    July 15th, 2010 at 8:50 am

    Thankyou for the post.
    I am able to solve the issue.

    Reply to this comment

Leave a Comment

blank