2010-07-25 101 views
4

不知道我是否缺少一些東西。當使一個演員遙控時,主要方法不會終止。如何殺死RemoteActor?

下面是顯示問題的代碼片段。

 
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 
    } 
} 

回答

4

將您的.alive和.register調用放在act()中,並且您的代碼成功終止。

+0

謝謝你解決我的問題! 如果這些方法在錯誤的上下文中調用時會失敗,那將會很不錯。 – Willem 2010-07-26 06:52:35