Akka Dispatcher Inheritance

I work with Akka and we are still going to get to know each other.

My scenario: I chose a non-default manager for the supervisor (parent) whose role is to manage (control) and create child entities to do the work.

Question: Do children of the parent actor act ?

I know that you can explicitly specify a different dispatcher for child participants from the parent players specified in the setting.

akka.actor.deployment { /my-parent-actor { dispatcher = dispatcher-for-parent } "/my-parent-actor/*" { dispatcher = dispatcher-for-children } } 

My question is, if you specify the dispatcher of the parent actor without explicitly specifying the dispatcher for child players, there is inheritance for the children of the parent actor.

+8
inheritance scala akka parent-child dispatcher
source share
1 answer

From what I saw, the child by default does not inherit the parent supervisor. I could not find this explicitly in the docs anywhere, so I wrote a quick piece of code to test my initial assumption:

 import com.typesafe.config.ConfigFactory import akka.actor._ object DispatcherTest extends App{ val conf = ConfigFactory.parseString(""" { my-custom-dispatcher { executor = "thread-pool-executor" type = PinnedDispatcher } } """) val system = ActorSystem("test", conf) val supervisor = system.actorOf(Props[MySupervisor].withDispatcher("my-custom-dispatcher")) } class MySupervisor extends Actor{ println(s"I am the supervisor, my dispatcher is: ${context.dispatcher}") val child = context.actorOf(Props[MyChild]) def receive = { case _ => } } class MyChild extends Actor{ println(s"I am the child, my dispatcher is: ${context.dispatcher}") def receive = { case _ => } } 

If you run this, you will see:

 I am the supervisor, my dispatcher is: PinnedDispatcher[my-custom-dispatcher] I am the child, my dispatcher is: Dispatcher[akka.actor.default-dispatcher] 
+14
source share

All Articles