1

Take a look at the code snippet:

import scala.actors.Actor._

object ActorTest1 extends Application {
  val caller = self

  val badActor = actor {
     receive {
        case msg =>
          println(Thread.currentThread()+ " "+msg)
          caller ! "bbbb"
     }
  }

  badActor ! "aaaa"
  receive {
     case a: String => println(Thread.currentThread() + " " + a)
  }

}

After badActor resonse "bbbb" to the sender, the whole application block . but if I change caller ! "bbbb" to sender ! "bbbb", it will work.

Could anyone explain why ?

爱国者
  • 4,298
  • 9
  • 47
  • 66

1 Answers1

2

i think that your caller reference is actually a reference to self, which is not an actor instance! :-)

instead sender is a a valid instance, as you can see here: http://doc.akka.io/docs/akka/snapshot/scala/actors.html

Alfredo Serafini
  • 195
  • 3
  • 13
  • starting from scala 2.10 the actor system is deprecated, and replaced with akka: http://docs.scala-lang.org/overviews/core/actors-migration-guide.html – Alfredo Serafini Apr 21 '13 at 19:59