为什么我的actor死锁了??

xuyaogyo 2012-12-18
object ActorTest {

    System.setProperty("actors.corePoolSize", "2")
    System.setProperty("actors.maxPoolSize", "4")

    val aQue = new SynchronousQueue[Runnable]();
    val bQue = new SynchronousQueue[Runnable]();

    val aScheduler = ExecutorScheduler(new ThreadPoolExecutor(2,
        2,
        60000L,
        TimeUnit.MILLISECONDS,
        aQue,
        new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy))

    //aScheduler.start()

    val bScheduler = ExecutorScheduler(new ThreadPoolExecutor(2,
        4,
        60000L,
        TimeUnit.MILLISECONDS,
        bQue,
        new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy))
    //bScheduler.start()


    def main(args: Array[String]) {

        for (i <- 1 to 50) {
            myActor({
                val outActor = self
                println("hello ,this is " + i)
                Thread.sleep(300)

                myActor({
                    println("inner actor-" + i)
                    Thread.sleep(300)
                    outActor ! "hello"
                    println("inner finish-" + i)
                }, bScheduler)

                println("hello ,finish is " + i)

                receive {
                    case _ => {
                        println(i + "-receive_")
                    }
                }



            }, aScheduler)
        }
    }

    def myActor(body: => Unit, iScheduler: IScheduler): Actor = {
        val a = new Actor {
            def act() = body

            override final val scheduler: IScheduler = iScheduler
        }
        a.start()
        a
    }
}
Global site tag (gtag.js) - Google Analytics