我知道sender在Future或调度程序中关闭方法调用或actor的内部状态是不安全的,但是actor的上下文呢?什么在ActorContext?在调度程序或将来的回调中关闭actor上下文是否安全?:
def receive: Receive = {
case Msg =>
system.scheduler.scheduleOnce(1 second) {
context.actorOf[ChildActor]
}
}
Run Code Online (Sandbox Code Playgroud)
不,关闭演员背景是不安全的.来自akka来源:
/**
* Stores the context for this actor, including self, and sender.
* It is implicit to support operations such as `forward`.
*
* WARNING: Only valid within the Actor itself, so do not close over it and
* publish it to other threads!
*
* [[akka.actor.ActorContext]] is the Scala API. `getContext` returns a
* [[akka.actor.UntypedActorContext]], which is the Java API of the actor
* context.
*/
implicit val context: ActorContext = { ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
872 次 |
| 最近记录: |