Akka (5) — Scheduler

haimei
play-hard-work-hard
1 min readApr 21, 2016

The default implementation of Scheduler used by Akka is based on job buckets which are emptied according to a fixed schedule. The scheduler method returns an instance of akka.actor.Scheduler which is unique per ActorSystem and is used internally for scheduling things to happen at specific points in time.

Scheduler implementation are loaded reflectively at ActorSystem start-up with the following constructor arguments:

  • the system’s com.typesafe.config.Config (from system.settings.config)
  • a akka.ever.LoggingAdapter
  • a java.util.concurrent.ThreadFactory

You can schedule sending of message to actors and execution of tasks (functions or Runnable). You will get a Cancellable back that you can call cancel on to cancel the execution of the scheduled operation. Cancels this Cancellable and returns true if that was successful. If this cancellable was (concurrently) cancelled already, then this method will return false though isCancelled will return true.

Cancellation flow:

  • a cancellation signal set by a consumer is propagated to its producer.
  • the producer uses onCancellation on Promise to listen to this signal and act accordingly.

--

--