本文介绍了如何为期货配置微调线程池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scala的期货线程池有多大?

How large is Scala's thread pool for futures?

我的Scala应用程序生成了数百万个future {},我想知道是否可以通过配置线程池来优化它们.

My Scala application makes many millions of future {}s and I wonder if there is anything I can do to optimize them by configuring a thread pool.

谢谢.

推荐答案

您可以指定自己的期货将在其中运行的ExecutionContext,而不是导入全局隐式ExecutionContext.

You can specify your own ExecutionContext that your futures will run in, instead of importing the global implicit ExecutionContext.

import java.util.concurrent.Executors
import scala.concurrent._

implicit val ec = new ExecutionContext {
    val threadPool = Executors.newFixedThreadPool(1000)

    def execute(runnable: Runnable) {
        threadPool.submit(runnable)
    }

    def reportFailure(t: Throwable) {}
}

这篇关于如何为期货配置微调线程池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 05:37