Michael Michael - 4 months ago 44
Scala Question

Scheduled Executor in Scala

In Java I can use Scheduled Executor to schedule tasks to run after a given delay. I can use it in Scala but I wonder if there is a Scala API for that.

Is there any Scala API (as opposed to

Scheduled Executor
in Java) to schedule tasks?


Akka has something similar with schedulers:


You can obtain one from the actor system:

val actorSystem = ActorSystem()
val scheduler = actorSystem.scheduler
val task = new Runnable { def run() { log.info("Hello") } }
implicit val executor = actorSystem.dispatcher

  initialDelay = Duration(5, TimeUnit.SECONDS),
  interval = Duration(10, TimeUnit.SECONDS),
  runnable = task)

If you are using Akka or something based on it, like Play, that would be the way to go.