playframework 2.2 创建定时任务计划程序

通过AkkA及Ator 在play2下实现任务计划程序的开发。


操作流程:

创建全局配置类文件

/app/Global.scala

代码内容如下: 



/** * Created by Administrator on 15-11-18. */import play.api.GlobalSettingsimport play.api.Applicationimport play.api._import play.libs.Akkaimport akka.actor._import scala.concurrent.duration._import play.api.libs.concurrent.Execution.Implicits._object Global extends GlobalSettings { override def onStart(app: Application) { println("start schedule plan!") Logger.info("hello, index action started") val Tick = "tick" val Tack = "tack" val tickActor = Akka.system.actorOf(Props(new Actor { def receive = { case Tick => Logger.info("that still ticks!") case Tack => Logger.warn("... 7 seconds after start, only once") } })) // Repeat every 5 seconds, start 5 seconds after start Akka.system.scheduler.schedule( 5 seconds, 5 seconds, tickActor, Tick ) // do only once, 7 seconds after start Akka.system.scheduler.scheduleOnce(7 seconds, tickActor, Tack) } }
阅读更多
个人分类: Play Framework
上一篇How to schedule task daily + onStart() in Play 2.0.4?
下一篇Scala中List的ListBuffer实现高效的遍历计算
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭