Akka学习笔记04--Actor生命周期

actor的生命周期大致上可分为下面三种阶段:

•初始化和启动

•通过执行特定的行为来接收和处理消息。

•当接收到终止命令时,停止。

此外,当actor的生命周期改变时,我们可以运用一些额外的可选方法(hooks)控制这些状态:

•重写preStart()和postStop()方法:可以初始化/清空任何actor资源。

•重写preRestart() 和 postRestart() :当出现异常或者上层actor重启当前actor时,用于控制状态。


原文:

**********************************************************************************************************************

An actor's lifecycle broadly consists of three phases as follows:

• Actor is initialized and started

• Actor receives and processes messages by executing a specific behavior

• Actor stops itself when it receives a termination message

Additionally, an Akka actor has additional, optional hooks that can be used to manage the state where it experiences a lifecycle change. The additional hooks are as follows:

• preStart() and postStop() can be implemented to initialize/clean any resources used by the actor to process the messages

• preRestart() and postRestart() allow the actor to manage the state in case an exception has been raised and Supervisor actor restarts the actor



tips:翻译于《Akka.Essentials》第三章,可能会有出入。附上原文。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值