SpringBoot Project Optimization and JVM Tuning Guide
This article provides a step‑by‑step guide on optimizing SpringBoot projects by modifying configuration files and tuning JVM parameters, covering both IDE‑based VM options and command‑line scripts, with detailed explanations of each setting and practical examples.
As a backend engineer, mastering project optimization is essential. In SpringBoot projects, optimization is mainly performed by editing the application.properties file and adjusting JVM parameters.
1. Modify Configuration File – The official SpringBoot documentation lists important properties such as server.tomcat.max-connections=0 , server.tomcat.max-http-header-size=0 , server.tomcat.max-http-post-size=0 , server.tomcat.max-threads=0 , and server.tomcat.min-spare-threads=0 . Adjust these values according to your workload.
2. JVM Tuning – Oracle provides a comprehensive guide for JVM tuning ( link ). The article demonstrates the default JVM settings (e.g., 8 GB max heap) and shows why they are often unreasonable.
3. Practical JVM Tuning
3.1 Without JVM Parameters – Running the application with default settings results in an oversized heap allocation, as shown by the screenshots.
3.2 Setting JVM Parameters
Method 1 – IDE (e.g., IntelliJ IDEA) : Add the required options to the VM options field, such as:
-XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=128m
-Xms1024m
-Xmx1024m
-Xmn256m
-Xss256k
-XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGCAfter applying these options, the GC logs and heap allocation become normal.
Method 2 – Command Line : Package the project with Maven, then start it with the same JVM options:
java -jar myapp.jar \
-XX:MetaspaceSize=128m \
-XX:MaxMetaspaceSize=128m \
-Xms1024m \
-Xmx1024m \
-Xmn256m \
-Xss256k \
-XX:SurvivorRatio=8 \
-XX:+UseConcMarkSweepGCMonitoring after launch confirms the parameters are effective.
4. Explanation of Key Parameters
-XX:MetaspaceSize=128m # default Metaspace size
-XX:MaxMetaspaceSize=128m # maximum Metaspace size
-Xms1024m # initial heap size
-Xmx1024m # maximum heap size
-Xmn256m # young generation size
-Xss256k # thread stack size
-XX:SurvivorRatio=8 # young generation survivor ratio (8:2)
-XX:+UseConcMarkSweepGC # use CMS garbage collector
-XX:+PrintGCDetails # print detailed GC logsNote that since JDK 8, -XX:PermSize and -XX:MaxPermGen have been removed and replaced by Metaspace settings.
By following these steps, developers can efficiently tune SpringBoot applications for better performance and resource utilization.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
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.