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



17 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
    • #
      Swetha
      July 25th, 2011 at 11:47 pm

      Hi While Iam trying to run above command (tomcat6w //ES//Tomcat6) the window showing all the parameters is not opened and its giving me error …

      [2011-07-25 14:39:52] [427 prunsrv.c] [error]
      The operation completed successfully.
      [2011-07-25 14:39:52] [1336 prunsrv.c] [error]
      Load configuration failed

      Please help us ASAP.

      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
  8. #
    Radheshyam
    September 30th, 2010 at 7:47 pm

    Bulls Eye Hit. Thank you.

    Reply to this comment
  9. #
    Andy
    October 6th, 2010 at 11:45 am

    Great post, thanks for the tips!

    Reply to this comment
  10. #
    Tworogarf
    October 14th, 2010 at 1:00 am

    foam poly vynal acetate topical spray for varicella zoster virus clobetasol .05 dangers of valium fever for five days no symptoms mlt memorex soma cod delivery ketoprofen injection biaxin clarithromycin qtc geodon xopenex in pediatrics astragalus extract applied computers natural analogs for geologic co2 sequestration pdi brand benzalkonium chloride packets flo beds can we measure serum thyroglobulin ehsan amin fludarabine cyclophosphamide regimen aplastic anemia tbi epi in imaging facial moisturizers with spf tobramycin ophthalmic cat c15 issues conjugation of estar synagis how long until effective what is doxycycline hyclate used for xenical weight loss medicine yakov zel dovich loratadine medicine apo definition fml is a omniform file extension ambrotose woolworths financial services gfs richard umbers asacol drug tory webber called drug protonix virgil brown ezetimibe 2008 vigamox how many times a day enbrel patient story dextromethorphan and phantom pain coughing up mucos trazodone side effects dose related acne medicine trinessa uaa homer skf actuation system cheap symbicort feline and avian skeletal systems pediasure in australia contac lens black oxide process free ferrets in florida psyllium husk bfad ammonia storage alendronate 35 ndc usnea tincture i need to order bacteriostatic water dimethyl sulfoxide 99.5 appetite supress weightloss drops avail shipping micardis nandrolone decanoate liver toxic stanozolol winstrol vitamins injectable rheem integrity c8 24 dane county wisconsin alcohol treatment programs valerian panic attacks horseshoe peg distance zolpidem somit side effects off atorvastatin generic finasteride identification codesp instructional aide tutorial uva enoteca predates woolly adelgid winstrol anadrol does propranolol erase memories foot toxin removal zanaflex flexeril clk wallpaper enteric coated aspirin coronary artery disease does accutane work sora no iro dyne test solutions james wands reme order vermox tablets plaster how-to repair holes sona nutrition zostavax local skin reactions high off focalin define articular cartilage tapazole tabs tandem tractors in the 60 s water jel fire blankets tazorac nra rifle qual patch papain safety dong quai root fever 1987 cruisers in chateau vee specs dow tordon rtu topiramate alcoholism ascorbic acid for swollen ankles

    Reply to this comment
  11. #
    Steinar
    October 23rd, 2010 at 5:10 pm

    Thank you, thank you, thank you! I’ve been strugling with OutOfMemoryError for a while. Everywhere I’ve looked, the reference is to CATALINA_OPTS, but that did not change anything. The advice in this post fixed it!

    Reply to this comment
  12. #
    Alan
    March 25th, 2011 at 11:57 am

    Make sure that there is at least 1 blank space at the end of the setting on the previous line, and make sure that there are NO TRAILING SPACES after the 256m.

    Just spent an hour trying find what was causing the following
    [2011-03-25 13:37:54] [error] CreateJavaVM Failed
    [2011-03-25 13:37:54] [error] The system could not find the environment option that was entered.

    Reply to this comment
  13. #
    Mathias
    May 18th, 2011 at 12:01 pm

    This is not a solution; this just buys you some time. If you run out of PermGen space this means your class files are not unloaded for some reason. You will still run out of PermGen space sooner or later.

    Reply to this comment
  14. #
    Chompy
    November 23rd, 2011 at 2:08 pm

    It solves the problem when you app too big. Thank!

    Reply to this comment
  15. #
    Brad
    February 2nd, 2012 at 10:30 am

    Nice post. Thanks.

    Reply to this comment

Leave a Comment

blank