简体   繁体   中英

When should an Actor be created in the Actor System vs Actor Context?

In Akka when should I create an Actor using system.actorOf() vs context.actorOf() ?

I know context.actorOf() creates a child actor, but when should one actor be a child of another vs top level?

you should avoid creating actors under the System actor. It's usually a good strategy to have new Actors as Children of your own (context) actor and group them accordingly and hierarchically.

That way you have better granularity to control the life cycle of your Actors, which implies you can control how many instances of each type of actor you need at any time (dynamically).

http://doc.akka.io/docs/akka/2.4/scala/actors.html

http://getakka.net/docs/Actor%20lifecycle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM