I know basic difference between the Akka dispatcher vs Global Execution context.
I tried this code with 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()
The Above code prints on an average the time equal to Thread.sleep(), around 103 milliseconds on an average.
However following code prints the time taken between 100-400 millisecond.
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()
I'm failing to understand what's the major difference apart from thread-pool
used.