How to Increase Apache Tomcat Heap Memory Size

Apache Tomcat commonly used to run web apps, commonly made by Java or Spring Boot. It's trusted and well known for it's realibility and easy to maintain. But ever wonder somehow you got Out of Memory Error from your web app? And how to deal with it?

Disclaimer: Not all Out of Memory means that you need to increase your heap size. Please make sure that you didn't use too much explicit objects that could have memory leaks, or check wether your un-optimized code causes this.

Increasing Heap Memory from your Java installation might not help much. Each instance have it's own limiter on using Heap Sizes. So does Apache Tomcat. But is it a bad news?

No, it's not a bad news at all. In fact, Apache Tomcat has a GUI to help you set the memory used by Apache Tomcat easily. To do this, please follow this step:

  1. Go to your Apache Tomcat install directory then go to the BIN folder (if you're using Tomcat 9, the path sould be C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin)
  2. Open tomcat[v]w.exe where v here is a version number. For example: tomcat9w.exe
  3. Go to the Java tab
  4. There you could set Initial memory pool and Maximum memory pool as you like, and leave Thread stack size empty.
    1. For Best Practice, set Initial and Maximum memory pool the same value (example: both 2048)
  5. Back to General Tab
    1. Click Start if the server hasn't started yet.
    2. If you already start the Tomcat Server, click restart. If restart button is disabled, click stop and when it's stopped, click start.
  6. Go to localhost:8080/manager/status to see the increased memory (change the port according to your setup)
Now you got increased memory.
But Tomcat somehow use not the exact same amount that we enter.
For example, I'm entering 3072 MB as Initial and Maximum, but in the Status page, I see the Tomcat only use around 2944 MB or maximum memory. But it's not a big problem since it's just a small difference.

There are multiple ways beside using GUI. You could use command line method or by editing catalina.bat. See full instruction in this website:


Hope this helps. Thanks for reading!
Note: I'm not the expert on this, I'm just taking notes of solutions for my problems. If you still got further problem, don't hestitate to open new question on StackOverflow. Thankyou.

Comments

Popular posts from this blog

How To Prevent Default Save to Onedrive at Save Dialog - Microsoft Office 2019