type
status
date
slug
summary
tags
category
icon
password

reactor模式组件

事件驱动,ReactorIO事件轮询,dispatch事件分发器,Handle处理器

单reactor单线程模式

notion image
AcceptHandler — 建立连接
read-write — 业务处理 在一个Thread中处理
核心api:
  • selctkey.attach() — 附加对象到选择键
  • selectKey.attachment() — 获取添加的选择键
问题:没办法充分利用cpu,一旦其中一个handle发生阻塞,可能导致其它handler执行不到

单reactor多线程模式

notion image
AcceptHandler — 建立连接
read-write - Thread只处理读写
业务处理 — 交给业务处理线程池

多reactor多线程模式

notion image
BossReactor — 专门处理Accept事件
WorkerReactor — 处理读写和业务handler

多reactor多线程模式+线程池

notion image