如何在 Scala 中编写计时器角色? [英] How to write a timer actor in Scala?
本文介绍了如何在 Scala 中编写计时器角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个演员每分钟发送一条消息.我如何最好地实现这种行为?我害怕使用 java.lang.Thread.sleep(long millis)
作为线程可以在 Scala 中的许多参与者之间共享,据我所知.
I need an actor to send a message every minute. How do I best achieve this behaviour? I am afraid of using java.lang.Thread.sleep(long millis)
as a thread can be shared among many actors in Scala, as far as I understand.
推荐答案
使用 receiveWithin
创建一个 actor 作为计时器.
Create an actor with receiveWithin
to act as the timer.
这篇关于如何在 Scala 中编写计时器角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文