Akka控制线程池线程
可能是一个非常愚蠢的问题——
是否可以自定义 Akka/Scala actor 以便控制 actor 使用的线程?例如,您可以初始化要在线程池中使用的自己的线程集,或者以其他方式控制/修改线程吗?
Potentially a very silly question--
Is it possible to customize Akka/Scala actors such that you control the threads that are used by the actors? e.g. can you initialize your own set of threads to be used in the thread pool, or otherwise control/modify the threads?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Akka 中,线程池是通过 MessageDispatcher 实例进行管理的。您可以轻松地为参与者设置您想要的调度程序:
要提供您自己的调度程序,您可以扩展akka.dispatch.MessageDispatcher(请参阅现有调度程序实现的示例)。在这里你可以直接玩线程。
当然,将业务逻辑放入调度程序中是危险的,因为它可能会破坏参与者模型并增加并发错误的数量......
In Akka, the thread pool is managed via a MessageDispatcher instance. You can set the dispatcher you want to actors easily:
To provide your own dispatcher, you can extend
akka.dispatch.MessageDispatcher
(see existing dispatchers implementation for examples). Here you can play directly with the threads.Of course, it's dangerous to put business logic inside a dispatcher because it may break the actor model and increase the number of concurrency bugs...
我试图自己理解它,但 Akka 中的人似乎不希望线程管理暴露在公众面前。
ThreadPoolConfig - 负责创建ExecutorService实例的类是一个案例类,其方法createExecutorService()声明为final!
因此,我没有看到提供自己的 ExecutorService 的简单方法。
I tried to understand it myself, but seams that guys in Akka don't want thread management to be exposed to public.
ThreadPoolConfig - the class that is responsible for creation of ExecutorService instances is a case class with method createExecutorService() declared final!
So, I don't see an easy ways to provide your own ExecutorService.