Scala Akka执行上下文与未来全局上下文

Scala Akka执行上下文与未来全局上下文,scala,akka,threadpool,Scala,Akka,Threadpool,我知道Akka调度程序和全局执行上下文之间的基本区别 我用scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global val resultF = (0 to 100).map( x => Future { val startTime = System.currentTimeMillis()

我知道Akka调度程序和全局执行上下文之间的基本区别

我用
scala.concurrent.ExecutionContext.Implicits.global

import scala.concurrent.ExecutionContext.Implicits.global
  val resultF = (0 to 100).map(
    x =>
      Future {
        val startTime = System.currentTimeMillis()
        val task = Future {
          Thread.sleep(100)
          x
        }
        task.onSuccess {
          case result =>
            val timeRemaining = System.currentTimeMillis() - startTime
            println(s"$result $timeRemaining")
        }
    }
  )
  StdIn.readLine()
上面的代码平均打印的时间等于Thread.sleep(),平均大约103毫秒

但是,下面的代码打印100-400毫秒之间的时间

  val system = ActorSystem("test")
  implicit val executionContext = system.dispatcher
  val resultF = (0 to 100).map(
    x =>
      Future {
        val startTime = System.currentTimeMillis()
        val task = Future {
          Thread.sleep(100)
          x
        }
        task.onSuccess {
          case result =>
            val timeRemaining = System.currentTimeMillis() - startTime
            println(s"$result $timeRemaining")
        }
    }
  )
  StdIn.readLine()
除了所使用的
线程池
,我无法理解主要区别是什么

我无法理解除了使用线程池之外的主要区别是什么

唯一的区别是使用的线程池及其工作调度算法

Akka ActorSystem线程池是一个fork-join执行器,如中所述

“全局”默认ExecutionContext是一个工作线程池,请参见


请参见,例如,

W/o更精确的问题@我很了解调度员,但我不确定为什么上面两段代码有这么大的不同。