Beyond Tomcat: Which Spring Boot Embedded Server—Jetty or Undertow—Delivers the Best Performance?
The article examines Spring Boot’s three embedded servers—Tomcat, Jetty, and Undertow—explaining why the default Tomcat may become a bottleneck in high‑concurrency, low‑latency microservices, and provides step‑by‑step guidance for switching servers, configuring key parameters, and selecting the optimal server based on workload characteristics.
What is an Embedded Server?
In a Spring Boot application the web server is packaged inside the executable JAR and started together with the application, eliminating the need for a separate servlet container installation.
Embedded Server = Web server packaged inside the application and started together with it.
The JAR contains the application code and one of the three supported servlet containers: Tomcat, Jetty, or Undertow.
Why Use Embedded Servers?
Embedding the server removes complex environment dependencies, reduces deployment steps, simplifies scaling, and lowers operational cost, especially in micro‑service architectures. It enables a single‑command start, no extra server installation, and seamless Docker/Kubernetes integration.
Spring Boot’s Three Embedded Servers
Tomcat – stable, mature; suited for general‑purpose business systems.
Jetty – lightweight, flexible; suited for long‑lived connections and streaming.
Undertow – non‑blocking, high‑performance; suited for high‑concurrency, low‑latency APIs.
Default Tomcat Configuration
Adding the spring-boot-starter-web dependency pulls in Tomcat, auto‑configures the servlet container, and starts an HTTP service.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>Switching to Jetty
Jetty offers lower memory usage, better WebSocket/long‑connection support, and faster startup.
Exclude Tomcat.
Add the Jetty starter.
<dependencies>
<!-- Exclude Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add Jetty -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>Switching to Undertow
Undertow uses a non‑blocking I/O model and an event‑driven architecture, allowing a few threads to handle many requests.
<dependencies>
<!-- Exclude Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add Undertow -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>Common Configuration Parameters
Configuration can be done via application.properties or application.yml regardless of the chosen server.
server.port=8081
server.servlet.context-path=/api
server.tomcat.max-threads=200 server:
port: 8081
servlet:
context-path: /api
tomcat:
max-threads: 200For Jetty or Undertow replace the tomcat prefix with jetty or undertow respectively.
Project Structure Example
/opt/projects/embedded-server-demo
├── pom.xml
├── src
│ ├── main
│ │ ├── java/com/icoderoad/Application.java
│ │ └── resources/application.yml
│ └── testServer Selection Guidance
General business systems: Tomcat (stable, default).
High‑concurrency API gateways: Undertow (best performance).
Long‑connection / real‑time communication: Jetty (strong connection management).
Performance Core Comparison
Tomcat allocates one thread per request, while Undertow can handle many requests with a small number of threads, reducing thread‑context overhead in high‑concurrency scenarios.
Conclusion
Performance bottlenecks often stem from the default embedded server rather than application code. Tomcat is reliable, but Jetty and Undertow provide distinct advantages for specific workloads. Engineers should evaluate the default choice and switch when the workload demands better scalability or lower latency.
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.
LuTiao Programming
LuTiao Programming is a friendly community offering free programming lessons. We inspire learners to explore new ideas and technologies and quickly acquire job-ready skills.
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.
