I am evaluating Akka for the distributed service level, the following example prints Hello {n} 10 times, but does it one by one. As far as I understand, this is intentional for the actor, so where can I go from here to make it parallel?
import akka.actor._ object HelloActor { case class SayHello(message: String) } class HelloActor extends Actor { def receive = { case HelloActor.SayHello(message) => Thread.sleep(1000) println(message) } } object Main extends App { val system = ActorSystem("ActorSystem") val hello = system.actorOf(Props[HelloActor]) for (i <- 1 to 10) { hello ! HelloActor.SayHello(s"Hello $i") } }
I experimented with creating several actors from the main class, but this is somehow not the case, shouldn't I just call the actor and then handle the concurrency / create more actors myself? Can anyone give an example of this (preferably to modify the above code). I read and read, but it seems to me that I need to immediately accept this, and I feel that there is simply no key concept here.
source share