如何为actor指定线程池
我有一个使用全局线程池的现有 java/scala 应用程序。我想开始在项目中使用参与者,但希望应用程序中的所有内容都使用相同的池。
我知道我可以设置参与者使用的最大线程数,但更喜欢共享线程池。这是必要/合理的吗?是否可以指定参与者的线程池?
如果不可能/不推荐,那么在已经使用线程的应用程序中集成参与者时是否有任何经验规则?
谢谢。
I have an existing java/scala application using a global thread pool. I would like to start using actors in the project but would like everything in the app using the same pool.
I know I can set the maximum number of threads that actors use but would prefer sharing the thread pool. Is this necessary/reasonable, and is it possible to designate the actor's thread pool?
If it is not possible/recommended, are there any rules of thumb when integrating actors in apps that are already using threads?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信你可以做这样的事情:
I believe you can do something like this:
对于 Scala 2.8.1 来说是:
For Scala 2.8.1 it's:
但是重用 Actor 子系统使用的线程池非常容易。首先,您可以控制它的大小:
并且您可以对其调用工作:
它唯一缺少的是安排工作的能力。为此,我使用一个单独的
ScheduledExecutorService
,它是单线程,并在 actor 线程池上运行其工作:然后您可以使用它来安排任何事情:
But it's quite easy to re-use the thread pool used by the actor subsystem. Firstly you can control it's size:
And you can invoke work on it:
The only thing it lacks is the ability to schedule work. For this I use a separate
ScheduledExecutorService
which is single-threaded and runs its work on the actors thread pool:Then you can use this to schedule anything: