Akka execution context vs Future global context

Hi,

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.

I would guess, the size of the thread pool makes the difference. If you can
get 101 threads, all 101 tasks will be executed in parallel. If you have a
smaller thread pool, some tasks have to wait for the first batch to finish.

For example, if you have 32 threads, 32 tasks would finish after about
100ms, another 32 after about 200ms, another 32 after 300ms and the
remaining 5 after 400ms.

The files that make your example complete would be helpful. So your build.sbt and your application.conf I think is the minimal set.