Akka Stream - 定时器或调度程序,如 CRON [英] Akka Stream - Timer or Scheduler like CRON
本文介绍了Akka Stream - 定时器或调度程序,如 CRON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Scala 上使用 Akka Stream.我想设置一个每 24:00 运行的调度程序.我试图寻找它.但我找不到我想做的事.你能告诉我怎么写代码吗?
I use Akka Stream on Scala. I'd like to set a scheduler which runs on every 24:00. I tried to search for it. But I could't find what I want to do. Could you tell me how to write code?
推荐答案
在 Akka scheduler 中使用构建,见:http://doc.akka.io/docs/akka/current/scala/scheduler.html
Use the build in Akka scheduler, see: http://doc.akka.io/docs/akka/current/scala/scheduler.html
您可以像这样使用调度程序:
You can use the scheduler like:
system.scheduler.schedule(
initialDelay = FiniteDuration(/*offset to next 24:00*/),
interval = FiniteDuration(24, TimeUnit.HOURS),
receiver = self,
message = ScheduleAkkaStream
)
然后在actor中,当收到ScheduleAkkaStream时,运行作业
Then in the actor, when the ScheduleAkkaStream is received, run the job
这篇关于Akka Stream - 定时器或调度程序,如 CRON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文