Backend Development 6 min read

SpringBoot Project and JVM Tuning Guide

This article explains how to optimize a SpringBoot application by adjusting configuration files and JVM parameters, demonstrates practical tuning steps with and without IDE support, and provides detailed explanations of common JVM flags and their impact on performance.

Java Captain
Java Captain
Java Captain
SpringBoot Project and JVM Tuning Guide

As an engineer, mastering project optimization is essential. In a SpringBoot project, tuning is mainly performed by editing configuration files and setting JVM parameters.

Modify Configuration Files

The application.properties file can be adjusted according to the official SpringBoot documentation.

server.tomcat.max-connections=0  # Maximum number of connections the server accepts and processes at any given time.
server.tomcat.max-http-header-size=0  # Maximum size, in bytes, of the HTTP message header.
server.tomcat.max-http-post-size=0  # Maximum size, in bytes, of the HTTP post content.
server.tomcat.max-threads=0  # Maximum number of worker threads.
server.tomcat.min-spare-threads=0  # Minimum number of worker threads.

JVM Tuning

Oracle provides an official JVM tuning guide (https://docs.oracle.com/middleware/11119/wls/PERFM/jvm_tuning.htm#i1146060) for reference.

1. Running without JVM parameters

By default, the maximum heap allocation may be set to 8 GB, which is often unreasonable.

2. Setting JVM parameters

Example of a typical JVM parameter list:

-XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=128m
-Xms1024m -Xmx1024m -Xmn256m
-Xss256k -XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGC

Method 1 – IDE (e.g., IntelliJ IDEA)

Enter the parameters in the VM options of the run configuration and restart the application. The GC logs and heap allocation will reflect the new settings.

Method 2 – Command line / script

After packaging the project with Maven, run the jar with the desired JVM flags:

$ java -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC myapp-1.0.0.jar

The application will start with the specified memory and garbage‑collection settings.

Explanation of Common JVM Flags

-XX:MetaspaceSize=128m – initial size of Metaspace (metadata storage).

-XX:MaxMetaspaceSize=128m – maximum Metaspace size.

-Xms1024m – initial heap size.

-Xmx1024m – maximum heap size.

-Xmn256m – size of the young generation.

-Xss256k – thread stack size.

-XX:SurvivorRatio=8 – ratio of Eden to Survivor spaces (8:2).

-XX:+UseConcMarkSweepGC – selects the CMS garbage collector.

-XX:+PrintGCDetails – prints detailed GC logs.

Key Knowledge Points

Since JDK 8, PermGen has been removed; Metaspace replaces it.

Metaspace stores class metadata in native memory, eliminating the classic OutOfMemoryError: PermGen.

Although Metaspace can grow dynamically, it is advisable to limit its size with -XX:MaxMetaspaceSize to avoid uncontrolled memory consumption.

END

BackendJavaPerformanceconfigurationJVM TuningSpringBoot
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.