Tomcat internal uses Acceptor, Poller to handle the client Socket connection. Acceptor Poller model is similar to Reactor network programming model. There are many references about Reactor online, which will not be discussed here.

This paper will be introduced from the following aspects:

When are Acceptor and Poller launches

Acceptor Poller starts in the startInternal method of NioEndPoint. The startInternal method will be explained later on in the framework of Tomcat, but you can leave it at that.

Open the stack of called methods to see when the method is entered:

Start with the SpringBoot boot function:

The sping context calls a series of functions,

In the final phase of the Refresh function, the finishRefresh method is called

Come in is call startEmbeddedServletContainer method

All the way down there is the startInternal method, where the call stack is on the main thread, so it’s easy to get into this method

The Poller is started before the Acceptor thread is started.

You can also see that there is not just one Poller in the NioEndpoint, but an array of pollers

Acceptors are also an array (only 1 by default)

The following is the initialization of Poller

2. Poller initialization process

// Introduce Poller properties and initialization functions