How do I increase memory on Tomcat 7 when running as a Windows Service?

123,880

Solution 1

Assuming that you've downloaded and installed Tomcat as Windows Service Installer exe file from the Tomcat homepage, then check the Apache feather icon in the systray (or when absent, run Monitor Tomcat from the start menu). Doubleclick the feather icon and go to the Java tab. There you can configure the memory.

enter image description here

Restart the service to let the changes take effect.

Solution 2

The answer to my own question is, I think, to use tomcat7.exe:

cd $CATALINA_HOME
.\bin\service.bat install tomcat
.\bin\tomcat7.exe //US//tomcat7 --JvmMs=512 --JvmMx=1024 --JvmSs=1024

Also, you can launch the UI tool mentioned by BalusC without the system tray or using the installer with tomcat7w.exe

.\bin\tomcat7w.exe //ES//tomcat

An additional note to this:

Setting the --JvmXX parameters (through the UI tool or the command line) may not be enough. You may also need to specify the JVM memory values explicitly. From the command line it may look like this:

bin\tomcat7w.exe //US//tomcat7 --JavaOptions=-Xmx=1024;-Xms=512;..

Be careful not to override the other JavaOption values. You can try updating bin\service.bat or use the UI tool and append the java options (separate each value with a new line).

Solution 3

//ES/tomcat -> This may not work if you have changed the service name during the installation.

Either run the command without any service name

.\bin\tomcat7w.exe //ES

or with exact service name

.\bin\tomcat7w.exe //ES/YourServiceName

Solution 4

According to catalina.sh customizations should always go into your own setenv.sh (or setenv.bat respectively) eg:

CATALINA_OPTS='-Xms512m -Xmx1024m'

My guess is that setenv.bat will also be called when starting a service.I might be wrong, though, since I'm not a windows user.

Solution 5

If you are running a custom named service, you should see two executables in your Tomcat/bin directory
In my case with Tomcat 8

08/14/2019  10:24 PM           116,648 Tomcat-Custom.exe
08/14/2019  10:24 PM           119,720 Tomcat-Customw.exe
               2 File(s)        236,368 bytes

Running the "w" terminated executable will let you configure Xmx in the Java tab
enter image description here

Share:
123,880
Franky
Author by

Franky

Updated on July 09, 2022

Comments

  • Franky
    Franky almost 2 years

    I am trying to run Tomcat 7 as a Windows Service (XP and Windows 7).

    I see places to set the -Xmx and -Xms jvm args in catalina.bat, but I'm not sure how to do it when using $CATALINA_HOME/bin/service.bat install service-name. I looked around but the best I could find was that I needed to update windows registry key, though I'm not sure which one to edit.

    I'm hoping there's an easier way, is there?

    Update: I'm not using the windows installer mainly because I'm running multiple instances of tomcat on the same machine but with different ports (for reasons I'd rather not go into here). If I can use the installer with multiple instances using different ports, then I'd like to know how, but regardless, is it possible to do increase the memory on a tomcat windows service without the UI tools that come with the installer?

  • vissu
    vissu about 12 years
    Hai @BalusC, 1. I want to add the -XX:MaxPermSize. If i do like above as u said, is it enough? And also 2. I want to add -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled to catalina batch script. How can I? please guide me...
  • BalusC
    BalusC about 12 years
    @vissu: If you have new questions, press Ask Question button in right top.
  • ziggy
    ziggy over 11 years
    No. Setenv.bat does not get called when running as a servcie.
  • Ankita
    Ankita over 9 years
    I changed this and save.But when I try to start it again, the tomcat is not being started. Once I change back to default memory size, I am able to start tomcat again.
  • simon
    simon over 8 years
    downvote: setenv does not get called when running as a windows service.
  • Jose Gómez
    Jose Gómez about 8 years
    Or you can just run .\bin\tomcat7w.exe , even if you did not use the installation package.
  • Bob
    Bob about 8 years
    You can find more of these options here directory.utk.edu/docs/windows-service-howto.html Also you may need to quote the command line options if they have special characters in them (like when you set a path to javaagent for instance.) One more thing to note, is you can use ++JvmOptions=... to append it to the list instead of -- which removes everything else.
  • Yampeku
    Yampeku almost 8 years
    the ++JvmOptions is safer and enough in most cases, be careful with the --JvmOptions one
  • Vadzim
    Vadzim over 5 years
    The same dialog can be opened by running %CATALINA_HOME%\bin\tomcatXw.exe, where X is major version number. See also tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
  • MK Yung
    MK Yung almost 4 years
    This screen is helpful but I needed to use @bkumar's command to open it. The full command is tomcat7w.exe //ES/MyServiceNameOnTaskManager
  • Rushikesh Gaidhani
    Rushikesh Gaidhani over 2 years
    @MKYung you can also open the above tomcat properties by going into the bin folder of your installed/extracted tomcat folder, and executing tomcat7w.exe (Sample path: C:\tomcat\bin\tomcat7w.exe)