简体   繁体   中英

Lifecyle of an actor in actor model

I'm a newbie to actor model. Could anyone please explain the lifecycle of an actor in actor model? I've been looking for the answer in the documentation, but I couldn't find anything satisfactory.

I'm interested in what an actor does after it completes the onReceive() method - is it still alive or is it dead? Can we control its lifetime to say "don't die, wait there for the next message"? For example, with a round-robin router, if I set it to have 5 actors - would it always distribute the work across the same 5 actors? Or actors are destroyed and created anytime there is a message, but the maximum limit is always 5.

Thanks!

The Actor is always alive unless you explicitly "kill" it (or it crashes somehow). When it receives a message, it will "use" a thread, process the message, then go back to an "idle" state. When it receives another message, it becomes "active" again.

In the case of a round-robin router with 5 Actor s, it is the same 5 Actor s - the router does not create new ones each time a message is sent to the router.

The Actor model follows an "isolated mutability" (concurrency) model - it encapsulates state only to itself - other Actor s are not able to touch this state directly, they can only interact with it via message passing. The Actor s must be "alive" in order to keep the state.

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