NIO框架

When working with NIO, the natural question we ask is how we're going to process a particullar NIO event, which occurred on an NIO channel. Usually we have two options: process the NIO event in the current (Selector) thread or pass it to the worker thread for processing.

Worker-thread IOStrategy.

The most useful IOStrategy, where Selector thread delegates NIO events processing to a worker threads. This IOStrategy is very scalable and safe. We can change the size of selector and worker thread pool as required and there is no risk that some problem, which may occur during the specific NIO event processing, will impact other Channels registered on the same Selector.

Same-thread IOStrategy.

Leader-follower IOStrategy.

可能的过程是,线程a收到事件,把channel丢给线程b,然后自己处理事件。如果线程b后续也收到事件,就把channel丢给线程a,然后自己处理事件。目的是为了高效地处理网络事件。

猜你喜欢

转载自wwyolandachang.iteye.com/blog/1329584