How to increase Java heap space for a tomcat app

前端 未结 10 2365
攒了一身酷
攒了一身酷 2020-12-08 09:59

There are lots of questions that ask this or a similar question.

They all give the command that has to be executed, what I don\'t understand is where do I write this

相关标签:
10条回答
  • 2020-12-08 10:52

    For Windows Service, you need to run tomcat9w.exe (or 6w/7w/8w) depending on your version of tomcat. First, make sure tomcat is stopped. Then double click on tomcat9w.exe. Navigate to the Java tab. If you know you have 64 bit Windows with 64 bit Java and 64 bit Tomcat, then feel free to set the memory higher than 512. You'll need to do some task manager monitoring to determine how high to set it. For most apps developed in 2019... I'd recommend an initial memory pool of 1024, and the maximum memory pool of 2048. Of course if your computer has tons of RAM... feel free to go as high as you want. Also, see this answer: How to increase Maximum Memory Pool Size? Apache Tomcat 9

    0 讨论(0)
  • 2020-12-08 10:55

    if you are using Windows, it's very simple. Just go to System Environnement variables (right-clic Computer > Properties > Advanced System Parameters > Environnement Variables); create a new system variable with name = CATALINA_OPTS and value = -Xms512m -Xmx1024m. restart Tomcat and enjoy!

    0 讨论(0)
  • 2020-12-08 10:58

    Easiest way of doing is: (In Linux/Ububuntu e.t.c)

    Go to tomcat bin directory:

    cd /opt/tomcat8.5/bin
    

    create new file under bin directory "setenv.sh" and save below mention entries in it.

    export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
    export CATALINA_OPTS="$CATALINA_OPTS -Xmx2048m"
    export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
    

    and issue command:

    ./catalina.sh run
    

    In your catalina log file you can see entry like this:

    INFO [main] VersionLoggerListener.log Command line argument: -Xms512m
    INFO [main] VersionLoggerListener.log Command line argument: -Xmx2048m
    INFO [main] VersionLoggerListener.log Command line argument: -XX:MaxPermSize=256m
    

    Which confirms that above changes took place.

    Also, the value of "Xms512m" and "-Xmx2048m" can be modified accordingly in the setenv.sh file.

    Startup of tomcat could be done in two steps as well. cd /opt/tomcat8.5/bin

    Step #1
    run ./setenv.sh 
    Step #2
    ./startup.sh
    

    If you're using systemd edit:

    /usr/lib/systemd/system/tomcat8.service
    

    and set

    Environment=CATALINA_OPTS="-Xms512M -Xmx2048M -XX:MaxPermSize=256m"
    
    0 讨论(0)
  • 2020-12-08 11:04

    Your change may well be working. Does your application need a lot of memory - the stack trace shows some Image related features.

    I'm guessing that the error either happens right away, with a large file, or happens later after several requests.

    If the error happens right away, then you can increase memory still further, or investigate find out why so much memory is needed for one file.

    If the error happens after several requests, then you could have a memory leak - where objects are not being reclaimed by the garbage collector. Using a tool like JProfiler can help you monitor how much memory is being used by your VM and can help you see what is using that memory and why objects are not being reclaimed by the garbage collector.

    0 讨论(0)
提交回复
热议问题