How to configure a fine tuned thread pool for futures?

后端 未结 4 631
情书的邮戳
情书的邮戳 2020-11-28 02:16

How large is Scala\'s thread pool for futures?

My Scala application makes many millions of future {}s and I wonder if there is anything I can do to opti

4条回答
  •  旧巷少年郎
    2020-11-28 02:55

    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) {}
    }
    

提交回复
热议问题