Replacing Tomcat with Undertow in Spring Boot: Configuration Guide and Performance Comparison
This article explains how to replace Spring Boot's default embedded Tomcat with Undertow, details the configuration steps, compares their performance and memory usage through benchmark results, and concludes that Undertow offers superior efficiency for high‑concurrency Java backend applications.
Preface
In the Spring Boot framework, Tomcat is the most commonly used container and the default embedded servlet container. Spring Boot also supports the Undertow container, which can be easily swapped in place of Tomcat and offers better performance and lower memory consumption. This article explains how to use Undertow.
Tomcat Container in Spring Boot
Spring Boot is currently the most popular Java web framework. It frees developers from heavy XML configuration, allowing a complete web service to be created within minutes, greatly improving development efficiency. A web container is essential for any web project, and in Spring Boot the default embedded container is Tomcat.
Setting Up Undertow in Spring Boot
Tomcat is familiar to most Java developers as the most widely used servlet container. Besides Tomcat, Spring Boot can also use Undertow. By simply adding the Undertow dependency, the embedded container is switched to Undertow.
After configuring the dependency and rebuilding the project, the application starts with Undertow as the embedded container.
Why replace Tomcat with Undertow?
Comparison of Tomcat and Undertow
Tomcat, an Apache Foundation lightweight servlet container, supports Servlets and JSPs and includes an HTTP server. It is free and widely loved by developers, but it is written in Java and differs from the Apache HTTP server written in C.
Undertow, an open‑source product from Red Hat, is a flexible high‑performance web server written entirely in Java. It supports both blocking and non‑blocking I/O, can be embedded directly into Java projects, and fully supports Servlets and WebSockets, performing excellently under high concurrency.
Benchmark Results
QPS comparison:
Tomcat
Undertow
Memory usage comparison:
Tomcat
Undertow
The tests show that under high‑concurrency workloads, Tomcat performs weaker than Undertow. With the same hardware, Undertow delivers better throughput and lower memory consumption, and its newer versions use persistent connections by default, further improving concurrency handling. Therefore, Undertow is the preferred choice for high‑traffic backend systems.
Conclusion
Spring Boot allows you to use either Tomcat or Undertow as the HTTP server. In high‑concurrency scenarios, Undertow outperforms Tomcat. If your system faces heavy request loads, consider switching to Undertow to achieve significant performance gains.
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.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.
