There is no reliable way to know what “everything is done” means.
This is because operations are asynchronous, and if you were to observe
“oh! nothing is in any mailbox!” the next millisecond something may
actually be in the mailbox, because it was just being asynchonously added.

Shutting down the system, must be an explicit decision.
It’s not like in sychronous programming world where things just “surely
have ended”.

You have to call system.terminate to do this.

There also is the reaper pattern:
http://letitcrash.com/post/30165507578/shutdown-patterns-in-akka-2
The pattern is pretty old, but still applies.

-- 
Cheers,
Konrad 'ktoso <http://kto.so>' Malawski
Akka <http://akka.io/> @ Lightbend <http://lightbend.com/>

On February 1, 2018 at 7:23:21, [email protected] (
[email protected]) wrote:

Hi, Akka newbie here, I try the sample on Akka web site and notice the
ActorSystem still runs after the Actors have finished, and I have to hit
Enter to quit. Is there a way to shut down ActorSystem object once
everything is done? I already tried the suggestion to override the
reference.conf file with "akka.actor.guardian-supervisor-strategy = \"
akka.actor.StoppingSupervisorStrategy\"\n" but still no luck. I also
checked with folks on the other Akka chat room and they suggest using Akka
Streams instead of Akka Actors?? Any insight is greatly appreciated!

My public static void main()code:
=================================

Config myConfig =
ConfigFactory.parseString("akka.actor.guardian-supervisor-strategy =
\"akka.actor.StoppingSupervisorStrategy\"\n");
// load the normal config stack (system props, then application.conf,
then reference.conf)
Config regularConfig = ConfigFactory.load();
// override regular stack with myConfig
Config combined = myConfig.withFallback(regularConfig);
// put the result in between the overrides (system props) and defaults again
Config complete = ConfigFactory.load(combined);
// create ActorSystem
ActorSystem system = ActorSystem.create("actorSystem", complete);

final ActorRef taskManagerActor = system
        .actorOf(TaskManager.props(taskListList.size(),
                new FiniteDuration(30000, TimeUnit.MILLISECONDS)));
for (List<String> taskList : taskListList) {
  taskManagerActor.tell(new TaskActor.RunTaskMsg(taskList),
ActorRef.noSender());
}//end for


My TaskManager Actor has a match() to shut itself down and the system down:

===========================================================================

...

.match(TaskManager.TaskCompletedMsg.class, o -> {
  if (taskCounter == totalNumTasks) {
    System.out.println("\nAll child Actors have been stopped. Shutting
down TaskManager Actor...");
    getContext().stop(getSelf());
    System.out.println("\nAnd shutting down ActorSystem...");
    getContext().getSystem().terminate();
  }//end if
})

...

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups
"Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to