SpringBoot Project Optimization: Configuration Files and JVM Tuning
This article explains how to optimize a SpringBoot application by adjusting Tomcat settings in the application.properties file, tuning JVM parameters with examples, and demonstrates two practical methods—IDE configuration and command‑line scripts—to improve performance and resource usage.
Project Optimization
As a developer, mastering project optimization is essential. In a SpringBoot project, optimization is mainly performed by editing configuration files and tuning JVM parameters. The following guide provides practical steps and code examples.
1. Modify Configuration Files
The key configuration file is application.properties. Important Tomcat settings include:
server.tomcat.max-connections=0 # Maximum number of connections the server accepts at any 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 idle worker threads.2. JVM Tuning
Oracle provides an official guide for JVM tuning. Below are the most commonly used parameters.
3. JVM Tuning Practice
1. Situation Without JVM Parameters
Running the project with default settings shows a default maximum heap size of 8 GB, which is often unreasonable.
2. Setting JVM Parameters
Example of a full JVM argument list:
-XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGCMethod 1: When using an IDE such as IntelliJ IDEA, add the arguments to the VM options field.
After setting, the GC logs and heap allocation appear correct.
Method 2: For deployed projects, set JVM parameters in the startup script or command line.
First, clean and package the project:
mvn cleanThen package without tests:
mvn package -Dmaven.test.skip=trueNavigate to the directory containing the runnable JAR and start it with the desired JVM arguments:
$ java -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC newframe-1.0.0.jarMonitoring after startup shows that the heap and GC behavior follow the configured parameters.
The meaning of each JVM option is summarized below:
-XX:MetaspaceSize=128m (initial 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) -XX:+UseConcMarkSweepGC (use CMS garbage collector) -XX:+PrintGCDetails (print detailed GC logs)
Note: Since JDK 8, the PermGen space has been removed and replaced by Metaspace, which resides in native memory, eliminating the classic OutOfMemoryError: PermGen issue.
Happy learning and coding!
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.
