Actors and Threads

The previous example gave a good idea of what’s going on with actors, but it also raises a question. In the previous output we see that the two messages sent to depp were both processed by the same thread whereas the two messages sent to hanks were both processed by one other thread. This may give an impression that actors hold on to their threads, but that’s not true—in fact, on your machine you may even notice the actors switch threads.

Threads are to actors like service agents are to customers. When you call a customer service line, any available agent answers. If you drop the call and redial, the previous agent has moved on to another call and a totally random dude now answers. Only in an extreme coincidence would you ...

Get Pragmatic Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.