How many actors can be launched in scala?

假如想象 提交于 2019-12-04 09:43:46

I think it has to do with scala´s actor pool. It probably (I am still waiting on my book "Actors in Scala") creates a pool with four threads (perhaps related to your four core CPU) and assigns your actors to them. The problem is, that you use Thread.sleep. That appeals to a certain thread and bypasses scala´s actor to thread assignment.

There are essentially two kinds of actors in Scala (when using the standard Scala 2.8 actors): thread-based and event-based actors.

When you use receive (or receiveWithin), as in your example, you are creating thread-based actors, which are relatively heavyweight. There's a separate thread for each actor, which is blocked as long as the actor is waiting for a message.

When you use react instead of receive, your actor will be an event-based actor. Event-based actors are much more lightweight; there is not a one-to-one link between event-based actors and threads. You can easily create thousands of event-based actors.

I've written a blog post (and example application) with more detail.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!