首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Akka监管违约行为

Akka监管违约行为
EN

Stack Overflow用户
提问于 2019-01-17 02:01:03
回答 1查看 54关注 0票数 0

我在努力学习am阿克卡的监督策略。当我在下面有这样的代码时,我确实得到了这个

java.lang.ArithmeticException: /零

代码语言:javascript
运行
复制
case object CreateChildren
case class DivideNumbers(n: Int , d:Int)
object SuperVision extends App {
  val actorSystem = ActorSystem("SupervisingActorSystem")
  val actor = actorSystem.actorOf(Props[ParentActor], "ParentActor")
  actor ! CreateChildren
  val child1 = actorSystem.actorSelection("/user/ParentActor/childActor")
  child1 ! DivideNumbers(4,0)

class ParentActor extends Actor{
  override def receive: Receive = {
    case CreateChildren =>
      context.actorOf(Props[ChildActor], "childActor")
  }
}

  class ChildActor extends Actor{
    override def receive: Receive = {
      case DivideNumbers(n,d) => println(n/d)

    }
  }

  actorSystem.terminate()
}

但是,当我没有儿童演员创造,并有这样的东西,我没有看到例外。

代码语言:javascript
运行
复制
val actorSystem = ActorSystem("SupervisingActorSystem")
  val actor = actorSystem.actorOf(Props[ParentActor], "ParentActor")
  actor ! DivideNumbers(4, 2)

  class ParentActor extends Actor {
    override def receive: Receive = {
      case DivideNumbers(n, d) => println(n / d)
      //case DivideNumbers(n, d) => throw new Exception
      //Even this doesn't throw an exception
    }
  }

  actorSystem.terminate()
  1. 为什么我没有看到例外,我是不是遗漏了什么?
  2. 这种行为背后的原因是什么?
  3. 当我们只有一个演员没有孩子的时候,什么是处理异常的好方法?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-17 02:21:32

您没有得到该异常仅仅是因为在异常引发之前,您的参与者系统已被终止,然后应用程序退出。

尝试在Thread.sleep(1000)之前添加actorSystem.terminate(),您将看到异常。

顺便说一句:这种行为与if you use only one actor or with a child无关。如果您使用一个子程序,仅仅因为它是一个与时间序列相关的随机行为,就会得到异常。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54227963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档