Backend Development 7 min read

Optimizing Spring Boot Embedded Tomcat and JVM Settings with Remote Debugging and Monitoring

This article explains how to configure and tune Spring Boot's embedded Tomcat, adjust JVM parameters, enable remote debugging, and connect monitoring tools such as JConsole and JVisualVM, providing practical steps and code examples for improved performance and easier troubleshooting in production environments.

Java Captain
Java Captain
Java Captain
Optimizing Spring Boot Embedded Tomcat and JVM Settings with Remote Debugging and Monitoring

Introduction

Spring Boot web projects use an embedded Tomcat server by default, which can also be switched to Jetty. Embedding the server simplifies micro‑service deployment and eliminates the need to download a separate Tomcat or Jetty installation.

Tomcat Optimization

Key points for container‑friendly tuning include thread counts, connection timeout, and JVM settings. A proper initial thread pool ensures stable handling of burst traffic, while a maximum thread limit protects system stability. Timeout settings prevent the server from being overwhelmed when many connections arrive.

server:
  tomcat:
    min-spare-threads: 20
    max-threads: 100
  connection-timeout: 5000

The above application.yml snippet sets the minimum spare threads to 20, the maximum threads to 100, and the connection timeout to 5000 ms.

JVM Optimization

Typical JVM tuning for a server includes using the -server mode and setting appropriate heap sizes. The initial and maximum heap are usually set to the same value based on the server’s memory capacity.

1. Use -server mode

java -server -jar springboot-1.0.jar

2. Specify heap parameters

Adjust the heap according to available memory:

-Xms : initial heap size

-Xmx : maximum heap size

java -server -Xms512m -Xmx768m -jar springboot-1.0.jar

This configuration sets the initial heap to 512 MB and the maximum heap to 768 MB.

3. Enable Remote Debugging

Start the application with JDWP options to allow remote debugging on port 8888:

java -Djavax.net.debug=ssl -Xdebug -Xnoagent -Djava.compiler=NONE \
 -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 \
 -jar springboot-1.0.jar

In IntelliJ IDEA, create a Remote Run/Debug configuration, set the host IP and port (8888), select the appropriate module, and start debugging. If a connection timeout occurs, disable the server firewall (e.g., systemctl stop firewalld.service and systemctl disable firewalld.service ).

JVM Tool Remote Connection

JConsole and JVisualVM Remote Access

To monitor a Spring Boot service remotely, adjust the server’s hostname and enable JMX:

java -jar -Djava.rmi.server.hostname=192.168.44.128 \
 -Dcom.sun.management.jmxremote \
 -Dcom.sun.management.jmxremote.port=911 \
 -Dcom.sun.management.jmxremote.ssl=false \
 -Dcom.sun.management.jmxremote.authenticate=false \
 springboot-1.0-SNAPSHOT.jar

Replace 192.168.44.128 with the actual server IP and 911 with the desired JMX port. After starting the application, open JConsole (or JVisualVM), enter the IP and port, and connect. The tools will display JVM metrics and allow remote debugging.

Both JConsole and JVisualVM provide similar remote connection capabilities; JVisualVM offers a richer UI and additional profiling features.

Conclusion

The steps above demonstrate how to fine‑tune Spring Boot’s embedded Tomcat, configure JVM options, enable remote debugging, and connect monitoring tools, helping developers achieve better performance and easier troubleshooting in production environments.

JVMperformance optimizationSpring BootTomcatremote debuggingJVisualVMJConsole
Java Captain
Written by

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.

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.