Will the actor system execute scheduled tasks when it gets termintaed

Hi

I have went through the akka documentation where it mentioned the below statement.

All scheduled task will be executed when theActorSystemis terminated, i.e. the task may execute before its timeout.

Below is the code I used to test this,


private static List<Cancellable> cancellableList = new ArrayList<>();

 public static void main(String args[]) throws Exception {
    system = ActorSystem.create("ReactorCluster");
    actorA = system.actorOf(Props.create(ActorA.class), "actorA");
    Cancellable c = getSystem()
        .scheduler()
        .scheduleOnce(Duration.ofSeconds(10), actorA, "hi", getSystem().dispatcher(), ActorRef.noSender());
    Cancellable c2 = getSystem()
        .scheduler()
        .scheduleOnce(Duration.ofSeconds(12), actorA, "hello", getSystem().dispatcher(), ActorRef.noSender());
    cancellableList.add(c);
    cancellableList.add(c2);
    system.terminate()
  }

Below is createReceive implementation for ActorA

@Override
  public Receive createReceive() {
    return receiveBuilder()
      .matchEquals("hi", h->{
        System.out.println("Hi");        
      })
      .matchEquals("hello", hello->{
          System.out.println("Hello");
      })
     .build();

But it is not printing hi and hello message in the console. Kindly guide me on this !!

The timer is shutdown after all the actors are stopped, which means your actor cannot verify it by receiving a message, the actor has already stopped.

Note that always running timer tasks on shutdown is changing for the upcoming Akka 2.6, see issue #16495 for details.