SoFunction
Updated on 2025-04-13

How to set JVM parameters when Tomcat starts

Set JVM parameters when Tomcat starts

Setting JVM parameters when Tomcat starts can be achieved by modifying Tomcat's startup script.

Under the Windows operating system, you can edit the "C:\apache-tomcat\bin\" file; under the Linux/macOS operating system, you can edit the "/opt/apache-tomcat/bin/" file.

The following are the specific steps:

  • Open the Tomcat installation directory and find the corresponding startup script file (or).
  • Open the file using a text editor (such as Notepad++, Sublime Text, vi, etc.).
  • Find the location of the JAVA_OPTS or CATALINA_OPTS variable in the startup script file. These variables are used to set JVM parameters.
  • Add the JVM parameters you need to set in the location found. For example, if you want to set the maximum heap memory to 512MB and the initial heap memory to 256MB, you can add it like this:

In Windows

set "JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx512m"
  • -Xms means the minimum size of JVM Heap (heap memory) is 128MB, initial allocation
  • -Xmx represents the maximum allowable size of JVM Heap (heap memory) 256MB, allocated on demand
  • PermSize and MaxPermSize indicate that the virtual machine permanently generates objects (Permanate generation) for Java, such as class objects and method objects, and these memory limits are not included in the Heap area.
  • NewSize/MaxNewSize: Define the size of the YOUNG segment,
  • NewSize is the memory size of YOUNG when JVM is started (young memory is the new generation in the heap, saving newly-listed objects);
  • MaxNewSize is the maximum YOUNG memory size that can be occupied.

In Linux/macOS

JAVA_OPTS="$JAVA_OPTS -Xms256m -Xmx512m"

Note that the above example sets the -Xms parameter to 256MB (initial heap memory) and the -Xmx parameter to 512MB (maximum heap memory). You can adjust these parameters according to your needs.

Save the file and close the editor.

Restart Tomcat. The JVM parameters of your settings will take effect when Tomcat starts.

Please note:

  • Certain JVM parameters, especially those involving performance and memory management, must be used with caution.
  • Make sure you understand the meaning and impact of each parameter to avoid configurations that may cause Tomcat performance to degrade or unstable.
  • It is best to verify the impact of any JVM parameters in the test environment before applying it to the production environment.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.