如何在Scala中编写计时器演员? [英] How to write a timer actor in Scala?

查看:128
本文介绍了如何在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 创建一个演员,以充当计时器。

Create an actor with receiveWithin to act as the timer.

这篇关于如何在Scala中编写计时器演员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆