Backend Development 7 min read

SpringBoot Project Optimization: Configuration File and JVM Tuning Guide

This article explains how to optimize a SpringBoot application by modifying the application.properties configuration file and tuning JVM parameters, providing practical code examples, IDE and script methods, and detailed explanations of each JVM option for better performance.

Top Architect
Top Architect
Top Architect
SpringBoot Project Optimization: Configuration File and JVM Tuning Guide

As a backend engineer, mastering project optimization is essential. In SpringBoot projects, optimization can be performed by adjusting configuration files and JVM parameters.

Modify Configuration Files

Details about editing application.properties are provided, with a reference to the official Spring Boot documentation.

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties

Important Tomcat settings include:

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

The Oracle JVM tuning guide is referenced for detailed explanations of JVM options.

https://docs.oracle.com/middleware/11119/wls/PERFM/jvm_tuning.htm#i1146060

JVM Tuning Practice

Scenario 1: Running a project without any JVM parameters results in a default maximum heap of 8 GB, which is often unreasonable.

Scenario 2: Setting JVM parameters manually.

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

Method 1: In IDEs such as IntelliJ IDEA, add the parameters to the VM options field and run the application.

Method 2: After packaging the project, start it from the command line with the desired JVM options.

mvn clean
mvn package -Dmaven.test.skip=true
$ java -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC newframe-1.0.0.jar

The JVM options mean the following:

-XX:MetaspaceSize=128m (default metaspace size)

-XX:MaxMetaspaceSize=128m (maximum metaspace size)

-Xms1024m (initial heap size)

-Xmx1024m (maximum heap size)

-Xmn256m (size of the young generation)

-Xss256k (maximum stack depth per thread)

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

-XX:+UseConcMarkSweepGC (use the CMS garbage collector)

-XX:+PrintGCDetails (print detailed GC logs)

Key points:

Since JDK 8, the PermGen space has been removed and replaced by Metaspace; the corresponding options are -XX:MetaspaceSize and -XX:MaxMetaspaceSize .

Metaspace resides in native memory, eliminating the classic java.lang.OutOfMemoryError: PermGen issue.

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

BackendJavaPerformanceconfigurationJVM TuningSpringBoot
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

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.