如何为参与者指定线程池 [英] How to designate a thread pool for actors

查看:112
本文介绍了如何为参与者指定线程池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用全局线程池的现有Java/scala应用程序.我想开始在项目中使用actor,但希望应用程序中的所有内容都使用同一池.

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.

我知道我可以设置actor使用的最大线程数,但希望共享线程池.这是必要/合理的,并且可以指定参与者的线程池吗?

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?

如果不可能/建议,在将actor集成到已经使用线程的应用程序中时,有什么经验法则吗?

If it is not possible/recommended, are there any rules of thumb when integrating actors in apps that are already using threads?

谢谢.

推荐答案

我相信您可以执行以下操作:

I believe you can do something like this:

trait MyActor extends Actor {
  val pool = ... // git yer thread pool here
  override def scheduler = new SchedulerAdapter {
    def execute(block: => Unit) =
      pool.execute(new Runnable {
        def run() { block }
      })
  }
} 

这篇关于如何为参与者指定线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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