加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 从Actor关闭Akka Actor系统

发布时间:2020-12-16 08:44:13 所属栏目:安全 来源:网络整理
导读:我知道我可以在actor系统之外使用system.shutdown()来停止actor系统并使system.awaitTermination()停止阻塞其线程上的执行. 我想从我的一个Actors中触发actor系统关闭.我以为我应该能够在Actor的receive方法中调用context.system.shutdown(),但是当我这样做
我知道我可以在actor系统之外使用system.shutdown()来停止actor系统并使system.awaitTermination()停止阻塞其线程上的执行.

我想从我的一个Actors中触发actor系统关闭.我以为我应该能够在Actor的receive方法中调用context.system.shutdown(),但是当我这样做时似乎没有发生任何事情,system.awaitTermination()(在主线程上)只是继续阻塞.

有任何想法吗?

解决方法

如何编程演员杀死自己

class WatchActor extends Actor {

   val child = context.actorOf(Props.empty,"child")
   context.watch(child) // <-- this is the only call needed for registration
   var lastSender = system.deadLetters

def receive = {
  case "kill" =>
   context.stop(child); lastSender = sender()
   case Terminated(`child`) => lastSender ! "finished"
  }
}

在这个网址上有一个很好的解释.

http://doc.akka.io/docs/akka/snapshot/scala/actors.html

JFM

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读