scala下实现actor多线程基础

package cn.huimin.test

import akka.actor._

object NewWrite extends App{
private val system = ActorSystem("newWrite")
private val talker: ActorRef = system.actorOf(Props[SimpleTalker],"talker")
talker ! HmInFifo("nihao")
talker ! aaa("dafd",12)
system.shutdown()
var flg = true
private val terminated: Boolean = system.isTerminated
println(terminated)
while (flg){
if(system.isTerminated){
flg = false
}
}
System.exit(0)
}
case class HmInFifo(name:String)
case class HmInFifo2(name:String)
case class aaa(name:String,age:Int)
class SimpleTalker extends Actor{
override def receive: Receive = {
case HmInFifo(name)=> println(s"adfsdaf $name")
case HmInFifo2(name)=>println(s"$name,adhfadjfl")
case aaa(name,age)=>{
println(s"my name is $name,and my age is $age")
Thread.sleep(5000)
}
}
}

posted @ 2018-09-18 10:42  Eilen  阅读(165)  评论(0编辑  收藏  举报