title: Blocking Operation in Actor NOT Occupying All Default Dispatchers
body: <p>I am learning Akka Actor recently. I read the document of dispatchers in Actor. I am curious about the blocking operation in an actor. The last <a href="http://doc.akka.io/docs/akka/current/scala/dispatchers.html#blocking-needs-careful-management" rel="nofollow noreferrer">topic</a> in the document describes how to solve the problem. And I am trying to reproduce the example experiment in the document.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package dispatcher
  
  import akka.actor.{ActorSystem, Props}
  import com.typesafe.config.ConfigFactory
  
  object Main extends App{
  
    var config = ConfigFactory.parseString(
      """
        |my-dispatcher{
        |type = Dispatcher
        |
        |executor = "fork-join-executor"
        |
        |fork-join-executor{
        |fixed-pool-size = 32
        |}
        |throughput = 1
        |}
      """.stripMargin)
  
  //  val system = ActorSystem("block", ConfigFactory.load("/Users/jiexray/IdeaProjects/ActorDemo/application.conf"))
  
  
    val system = ActorSystem("block")
  
  
    val actor1 = system.actorOf(Props(new BlockingFutureActor()))
    val actor2 = system.actorOf(Props(new PrintActor()))
  
    for(i &lt;- 1 to 1000){
      actor1 ! i
      actor2 ! i
    }
  
  }
  
  package dispatcher
  
  import akka.actor.Actor
  
  import scala.concurrent.{ExecutionContext, Future}
  
  class BlockingFutureActor extends Actor{
    override def receive: Receive = {
      case i: Int =&gt;
        Thread.sleep(5000)
        implicit val excutionContext: ExecutionContext = context.dispatcher
        Future {
          Thread.sleep(5000)
          println(s"Blocking future finished ${i}")
        }
    }
  }
  package dispatcher
  
  import akka.actor.Actor
  
  class PrintActor extends Actor{
    override def receive: Receive = {
      case i: Int =&gt;
        println(s"PrintActor: ${i}")
    }
  }
  </code></pre>
  
  <p>I simply create an <code>ActorSystem</code> with the default dispatchers and all actors depend on those. The <code>BlockingFutureActor</code> has a blocking operation that is encapsulated in a <code>Future</code>. The <code>PrintActor</code> is merely printing a number instantly. </p>
  
  <p>In the document's explanation, the default dispatchers will be occupied by  <code>Future</code>s in the <code>BlockingFutureActor</code>, which leads to the message blocking of the <code>PrintActor</code>. The application gets stuck somewhere like:</p>
  
  <pre><code>&gt;　PrintActor: 44
  &gt;　PrintActor: 45
  </code></pre>
  
  <p>Unfortunately, my code is not blocked. All outputs from <code>PrintActor</code> show up smoothly. But outputs from <code>BlockingFutureActor</code> show up like squeezing toothpaste. I try to monitor my thread info by Intellij's Debug, I got:
  <a href="https://i.stack.imgur.com/XHNAm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XHNAm.png" alt="thread monitoring"></a></p>
  
  <p>You may find only two dispatchers are sleeping(<code>BlockingFutureActor</code> makes this happen). Others are waiting, which means they are available for new message delivering. </p>
  
  <p>I have read an answer about blocking operation in Actor(<a href="https://stackoverflow.com/questions/44668898/starvation-of-akka-actors-who-participate-in-a-sequence-process/44671531#44671531">page</a>). It is quoted that "Dispatchers are, effectively, thread-pools. Separating the two guarantees that the slow, blocking operations don't starve the other. This approach, in general, is referred to as bulk-heading, because the idea is that if a part of the app fails, the rest remains responsive." </p>
  
  <p>Do default dispatchers spare some dispatcher for blocking operation? Such that the system can handle messages even if there are so many blocking operations asking for dispatchers.</p>
  
  <p>Can the experiment in the Akka document be reproduced? Is there something wrong with my configuration.</p>
  
  <p>Thanks for your suggestions. Best Wishes.</p>