“反应器模式”的说明 [英] Explanation of the "Reactor pattern"

查看:115
本文介绍了“反应器模式”的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以找到的反应堆模式的唯一解释是在维基百科,它有点抽象(imho) 。你可以用更具体的方式来描述这种模式吗?理想情况下,代码片段或高级类图?

The only explanation of the reactor pattern I could find is in wikipedia, and it's a bit too abstract (imho). Can you describe this pattern in a more concrete way.. ideally with code snippets or high level class diagrams?

推荐答案

使用单个线程有效地处理多个任务阻止(例如由于IO))。反应器管理一个处理程序池并运行事件循环。当它被调用来执行任务时,它将链接到一个新的或空的处理程序,使其处于活动状态。事件循环(1)查找所有处于活动状态和未阻塞状态的处理程序(或将其委托给调度程序实现)(2)依次执行这些找到的处理程序,直到它们完成或到达阻塞点。完成的处理程序变得无效并且空闲以供重用,而阻塞的活动处理程序产生,允许事件循环继续。 (3)从步骤(1)重复

A reactor allows multiple tasks which block (say due to IO) to be processed efficiently using a single thread. The reactor manages a pool of handlers and runs an event loop. When it is called to perform a task it links it with a new or vacant handler making it active. The event loop (1) finds all the handlers that are active and unblocked (or delegates this to a dispatcher implementation) (2) executes each of these found handlers sequentially until they either complete or reach a point where they block. Completed handlers become inactive and vacant for reuse whereas blocked active handlers yield, allowing the event loop to continue. (3) Repeats from step (1)

这篇关于“反应器模式”的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆