Say we have three Akka Actor
s, A
, B
and C
running on a dispatcher with only one Thread
and the following happens:
A
receives a message and starts processing itB
and simultaneously a message is sent to C
. Since there are no Thread
s available, both B
and C
put these messages in their mailboxA
now finishes processing its message and has no more messages in its mailbox, so releases the Thread
back into the poolB
or C
now both need this Thread
. Are there any guarantees for which will be put on the Thread first?
- How does Akka make this decision? Does it round robin on all
Actor
s in theActorSystem
?- Is this decision configurable?
- Can I say prioritise
Actor
C
to get Threads beforeActor
B
in these situations?
The whole reason why to use Akka is to not have to deal with this sort of thing. You do not want (or need) to prioritize actors in a way like this. Internal dispatcher logic is complex and very well optimized to process tasks as fast possible. Prioritization should be done through other means - like routers, or priority mailboxes.
Now to answer your question: the default dispatcher is backed by a blocking queue - the actor who first received the message in his mailbox will be selected first.