如何杀死RemoteActor? [英] How do I kill a RemoteActor?

查看:47
本文介绍了如何杀死RemoteActor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我是否缺少什么。将actor设置为远程时,main方法不会终止。

Not sure whether I am missing something. When making an actor remote, the main method does not terminate.

以下是演示该问题的代码段。

Here is a snippet that demonstrates the problem.


import scala.actors._
import scala.actors.remote._
object TestMe {
  def main(args : Array[String]) : Unit = {
      object jim extends DaemonActor {
          // comment out these two lines and the application will terminate
          RemoteActor.alive(12345)
          RemoteActor.register('jim,this)         
          def act {
              loop {
                  receive {
                      case 'quit =>
                       println("\nquiting")
                        exit('normal)
                      case any => 
                        println(any)
                  }
              }
          }
      }
      jim.start
      jim ! "hello"
      jim ! 'quit
  }
}


推荐答案

输入.alive和。在act()中注册调用,您的代码成功终止。

Put your .alive and .register calls inside act() and your code successfully terminates.

这篇关于如何杀死RemoteActor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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