2017-09-11 1 views
-1

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의 주요 차이점을 이해하지 못하는거야.

+1

더 정확한 질문 ... http://doc.akka.io/docs/akka/2.5/scala/dispatchers.html – cchantep

+0

@cchantep 나는 배차자를 잘 알고 있지만 나는 그렇지 않다. 왜 위의 두 코드 스 니펫에 많은 차이가 있는지 확인하십시오. – Atiq

답변

0

사용 된 스레드 풀과 다른 주요 차이점을 이해하는 데 실패했습니다.

유일한 차이점은 사용 된 스레드 풀과 작업 스케줄링 알고리즘입니다. http://doc.akka.io/docs/akka/2.5/scala/dispatchers.html

"글로벌"기본의 ExecutionContext에 설명 된대로

Akka ActorSystem의 스레드가 작업 훔치는 스레드 풀 포크 - 조인 집행 인이다, 예를 들어, 참조 https://github.com/scala/scala/blob/v2.12.3/src/library/scala/concurrent/ExecutionContext.scala#L135

How is the fork/join framework better than a thread pool?