After talking about server startup, let's take a look at the request processing process,After the server is started, the server is on standby and the request comes. The request processing process is divided into two phases:
- Request connection establishment process(ToNIOExample)
As mentioned above, a thread is allocated from the thread pool to wait for a new connection, that is, the listening thread. When there is no request, the thread is blocked inAccept()Method. When a new connection is established,AcceptMethod assignedSocketAnd set itNonblocking,The last thing to do isSocketToAcceptorThread(Basically equal opportunity)Processing, and then immediately return to continue in the accept state, can this thread work is quite simple, the efficiency is also quite high.
AcceptorThere are many threads(All come from the thread pool and are allocated in a fixed manner based onJetty. xmlIn configurationAcceptorsConfiguration quantity)Every thread maintainsSelectSet,EachSelectSetCorresponds to anotherSelector,These threads check whether there are tasks, suchChangesWhether there are tasks in the queue and there is a new connection, then quickly establishEndpoint