Loading

Tomcat NioEndPoint Architecture

Tomcat NioEndPoint Architecture

As a web server, how Tomcat implements the I/O models to complete communicate. In Tomcat NioEndPoint, it implement the I/O Multiplexing Model.

What the I/O Multiplexing Model indicates us to do? Let's see the picture in the before blog.

image-20210312234306285

image-20210312234447270

I/O Mutliplexing Model Implemention in Java

What does the multiplexing means?

That is one Selector manages many Channels. In other word, many Channels share a common Selector.

340654bd8f728ef324499e27533aa841.png

In Java, we would follow a simlpe description in two steps to implement.

  1. Create a Selector.

    Create some Channels.

    Register the Channels' interested thing (Connect, Accept, Read, Write, that's to say the Channel have four function) on Selector.

    The Selector call select to start to work, to exam and wait the registered interesting thing coming in a loop.

  2. When the interesting thing comes, e.g. The Read interesting thing comes.

    We would create a new thread to Read the data from that Channel.

In Tomcat, the NioEndPoint implement in the way downside.

image-20210313095003825

image-20210313005450779

posted @ 2021-03-13 00:56  齐玉  阅读(53)  评论(0)    收藏  举报