Spring Boot Project and JVM Tuning Guide
This article explains how to optimize Spring Boot applications by adjusting configuration properties and JVM parameters, provides essential Tomcat settings, demonstrates practical tuning steps with and without IDE support, and details the meaning of common JVM flags for improved performance.
As an engineer, mastering project optimization is essential.
In Spring Boot projects, tuning is mainly performed through configuration files and JVM parameters.
Modify Configuration Files
Details on editing the application.properties file are provided.
Important Tomcat properties 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 documentation provides a comprehensive guide for JVM tuning.
JVM Tuning Practice
1. Situation without JVM parameters
The project runs with default JVM settings, which allocate an 8 GB maximum heap—clearly unreasonable.
Heap allocation screenshot:
2. Setting JVM parameters
Example JVM parameter list:
-XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=128m
-Xms1024m -Xmx1024m -Xmn256m
-Xss256k -XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGCMethod One: If using an IDE such as IntelliJ IDEA, add the parameters to the VM options field.
After setting, GC logs and heap allocation appear correct.
GC log screenshot:
Heap allocation screenshot:
Method Two: Suitable for deployment scripts or command‑line launches.
Clean the old project:
mvn cleanPackage the new project: mvn package -Dmaven.test.skip=true Navigate to the runnable JAR directory and start with the JVM parameters:
$ java -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC newframe-1.0.0.jarMonitoring now shows the expected performance.
Explanation of the JVM flags (see the Oracle guide above):
-XX:MetaspaceSize=128m – initial 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 – selects the CMS garbage collector.
-XX:+PrintGCDetails – prints detailed GC logs.
Key points:
Since JDK 8, -XX:PermSize and -XX:MaxPermGen have been removed; they are replaced by Metaspace settings.
Metaspace stores class metadata in native memory, eliminating the classic OutOfMemoryError: PermGen issue.
Although Metaspace can grow dynamically, it should be limited with -XX:MaxMetaspaceSize to avoid uncontrolled memory usage.
(End)
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
