play framework 2.1 - scheduling async tasks

后端 未结 3 727
感情败类
感情败类 2020-12-15 08:34

In play\'s 2.0.x doc you can see how to schedule asynchronous tasks:

http://www.playframework.org/documentation/2.0.4/ScalaAkka

Akka.system.scheduler         


        
3条回答
  •  孤城傲影
    2020-12-15 09:23

    biesior's answer is great

    However, you don't have to go through an actor if you don't want to. Here's the same answer using good old java.lang.Runnable:

    Akka.system.scheduler.schedule(5 minutes, 5 minutes, new Runnable {
      def run() {
        Logger.info("that still ticks!")
      }
    })
    Akka.system.scheduler.scheduleOnce(7 minutes, new Runnable {
      def run() {
        Logger.warn("... 7 seconds after start, only once")
      }
    })
    

提交回复
热议问题