# Will the actor system execute scheduled tasks when it gets termintaed

**URL:** <https://discuss.akka.io/t/will-the-actor-system-execute-scheduled-tasks-when-it-gets-termintaed/5036>\
**Category:** Actors\
**Tags:** akka\
**Created:** [September 12, 2019, 6:55am UTC](https://discuss.akka.io/t/will-the-actor-system-execute-scheduled-tasks-when-it-gets-termintaed/5036 "2019-09-12T06:55:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilkumble](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anilkumble](https://discuss.akka.io/u/anilkumble)\
**Post date:** [September 12, 2019, 6:55am UTC](https://discuss.akka.io/t/will-the-actor-system-execute-scheduled-tasks-when-it-gets-termintaed/5036/1 "2019-09-12T06:55:57Z")

</div>

Hi

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

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

Below is the code I used to test this,

```auto

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

```auto
@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 !!

---

<div class="post-metadata">

**Author:** ![johanandren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/johanandren/32/85_2.png) [@johanandren](https://discuss.akka.io/u/johanandren)\
**Post date:** [September 12, 2019, 7:29am UTC](https://discuss.akka.io/t/will-the-actor-system-execute-scheduled-tasks-when-it-gets-termintaed/5036/2 "2019-09-12T07:29:37Z")

</div>

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](https://github.com/akka/akka/issues/16495) for details.
