Akka 디스패처 대 글로벌 실행 컨텍스트 간의 기본적인 차이점을 알고 있습니다. Akka 실행 컨텍스트 대 미래 글로벌 컨텍스트
는 I는 평균 103 밀리 주위에 평균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를 (동일 시간) 위의 코드를 인쇄 코드를 시도했다.
그러나 다음 코드는 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()
나는 떨어져 사용 thread-pool
의 주요 차이점을 이해하지 못하는거야.
더 정확한 질문 ... http://doc.akka.io/docs/akka/2.5/scala/dispatchers.html – cchantep
@cchantep 나는 배차자를 잘 알고 있지만 나는 그렇지 않다. 왜 위의 두 코드 스 니펫에 많은 차이가 있는지 확인하십시오. – Atiq