The Akka scheduler dwells on the exception; was this expected?

We run this code:

scheduler.schedule(1 minute, 1 minute) { triggerOperations.tick() } 

when you launch our application, in which the scheduler is Akka actorSystem.scheduler. If tick () throws an exception, then it is never called again!

I checked the documentation, but cannot find any statements that are expected. Basically, this description: "Schedule of a function that will be performed repeatedly with an initial delay and frequency", without mentioning that if the function throws excrement, the task will stop shooting.

Our version of akka is 2.3.2.

http://doc.akka.io/docs/akka/2.3.4/scala/scheduler.html http://doc.akka.io/api/akka/2.0/akka/actor/Scheduler.html

Is this behavior expected? Is it documented somewhere?

+5
source share
1 answer

If in doubt, go to the source. The code is a bit accurate, but this snippet:

  override def run(): Unit = { try { runnable.run() val driftNanos = clock() - getAndAdd(delay.toNanos) if (self.get != null) swap(schedule(executor, this, Duration.fromNanos(Math.max(delay.toNanos - driftNanos, 1)))) } catch { case _: SchedulerException ⇒ // ignore failure to enqueue or terminated target actor } 

}

shows that if your runnable throws, the scheduler does not transfer the next execution (what happens inside swap, as I understand it).

+5
source

All Articles