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,然后自己处理事件。目的是为了高效地处理网络事件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值