Search code examples
javaakkaactor

akka actors Toolkit - context.actorOf vs system.actorOf


Could you please explain to me what is the difference between

context.actorOf

and

system.actorOf

?


Solution

  • Answer to this can be easily found in the Akka documentation:

    An actor system is typically started by creating actors beneath the guardian actor using the ActorSystem.actorOf method and then using ActorContext.actorOf from within the created actors to spawn the actor tree.

    • Actors spawned with System.actorOf will be children of the guardian actor.
    • Actors spawned with context.actorOf will be children of the context itself - i.e. the actor which invokes the method.

    As a more general suggestion, make sure you thoroughly explore Akka docs when in search of similar answers.