This guide walks you through downloading, installing, and using VisualVM to profile a Spring Boot application with enhanced JVM flags for better profiling support.
- Java JDK (8 or higher)
- Spring Boot project (Maven-based)
- Maven (
mvn) installed - VisualVM
- Visit: https://visualvm.github.io
- Download the version for your OS:
- Windows:
.zipor.exe - macOS:
.dmg - Linux:
.tar.gz
- Windows:
- Extract and run:
- Windows:
visualvm.exe - macOS/Linux:
./bin/visualvm
- Windows:
π VisualVM may also be included in your JDK as
jvisualvm.
To expose runtime metrics in your Spring Boot app, add this to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Use the following Maven command to run your Spring Boot app with JVM options enabled for profiling, in Linux:
MAVEN_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=127.0.0.1" \
mvn spring-boot:runFor Windows, use the following command:
set MAVEN_OPTS=-Dcom.sun.management.jmxremote ^
-Dcom.sun.management.jmxremote.port=9010 ^
-Dcom.sun.management.jmxremote.local.only=false ^
-Dcom.sun.management.jmxremote.authenticate=false ^
-Dcom.sun.management.jmxremote.ssl=false ^
-Djava.rmi.server.hostname=127.0.0.1
mvn spring-boot:runThese flags allow:
-Dcom.sun.management.jmxremote: Enables JMX (Java Management Extensions)-Dcom.sun.management.jmxremote.port=9010: The port VisualVM connects to-Dcom.sun.management.jmxremote.local.only=false: Allows non-local connections (optional if local only)-Dcom.sun.management.jmxremote.authenticate=false: No username/password required-Dcom.sun.management.jmxremote.ssl=false: No SSL needed-Djava.rmi.server.hostname=127.0.0.1: Ensure correct RMI binding (important if issues occur)
- Launch VisualVM
- Look under "Local" for your Spring Boot process
- Double-click to view monitoring info
Navigate to the tabs:
- Monitor β CPU, heap, GC, threads
- Sampler β Low-overhead profiling
- Profiler β Detailed method-level analysis (more resource-intensive)
- Click Profiler β CPU β Start
- Use your app normally
- Click Stop to analyze performance
Check for:
- Hot methods (high CPU usage)
- Memory usage by class
- Thread contention
- GC overhead
Use insights to refactor and optimize performance.
Add this to application.properties:
management.endpoints.web.exposure.include=*
management.endpoint.metrics.enabled=trueThen access:
http://localhost:8080/actuator/metrics
Example sub-metric (e.g. JVM memory): π http://localhost:8080/actuator/metrics/jvm.memory.used
| Step | Description |
|---|---|
| 1 | Install VisualVM |
| 2 | Add Actuator (optional) |
| 3 | Run Spring Boot with JVM flags |
| 4 | Connect to app using VisualVM |
| 5 | Profile using Sampler/Profiler tabs |
| 6 | Analyze and optimize code |