Member-only story
1. Why replace the default tomcat?
Tomcat is a lightweight servlet container under the Apache Foundation that supports both servlets and JSPs. Tomcat has features unique to web servers, including the Tomcat Management and Control Platform, the Security Bureau Administration, and the Tomcat Valve. Tomcat itself contains an HTTP server, so it can also be thought of as a separate web server. In the SpringBoot framework, we use Tomcat the most, which is SpringBoot’s default container technology, and it is embedded Tomcat.
Comparison of Tomcat vs Undertow
Undertow is an open source product of Red Hat, developed entirely in Java, and is a flexible, high-performance web server that supports both blocking and non-blocking IOs. Since Undertow is developed in Java, it can be embedded directly into Java projects. At the same time, Undertow fully supports servlets and Web sockets, which is very good in high-concurrency situations.

We stress tested Tomcat and Undertow under the same machine configuration, and the test results are as follows:
Comparison of QPS test results:
Tomcat
Undertow
Through testing, it is found that Tomcat is relatively weak in high-concurrency systems. Simulating an equal number of requests with the same machine configuration, Undertow is optimal in terms of performance and memory usage. In addition, the new version of Undertow uses persistent connections by default, which will further improve its concurrent throughput capabilities. Therefore, if it is a high-concurrency business system, Undertow is the best choice.
2. Code engineering
Objectives of the experiment
Replace the default tomcat with undertow
pom.xml
Exclude tomcat first, then add the undertow dependency package
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0…