concept dispatcher in category scala

This is an excerpt from Manning's book Scala in Action.
Every actor system comes with a default MessageDispatcher component. Its responsibility is to send a message to the actor’s mailbox and execute the actor by invoking the receive block. Every MessageDispatcher is backed by a thread pool, which is easily configured using the configuration file (more about this in chapter 12). You can also configure various types of dispatchers for your actor system or specific actors. For this chapter we are going to use the default dispatcher (a.k.a event-based dispatcher). Figure 9.4 shows how sending and receiving messages works inside actors.
You use the router actors to increase the scalability of the application because they help in routing messages to multiple instances of actors, based on an algorithm. The next section discusses routers and dispatchers, two of the neat features of Akka.
Every actor system has a default dispatcher that’s used if nothing is configured. In Akka, message dispatchers are the engine behind the actors that makes Actor run. Think of a dispatcher as a service with a thread pool that knows how to execute actors when a message is received. In most scenarios, the default settings work best. In fact, when you’re building an Akka application, I recommend starting with that—don’t create a special configuration.
But if you notice some contention on a single dispatcher, you can start creating dedicated dispatchers for a group of actors. Assume you’re in that situation. You notice that your InternalPriceCalculatorActor and ExternalVendorProxyActor actors aren’t getting executed as quickly as you want, and it’s because of the contention in the default dispatcher. Remember, all the actors are created from the same actor system. You can easily configure the default dispatcher by adding more threads to it, but for learning purposes you’re going to use different dispatchers. Akka comes with four types of message dispatchers: