Using Akka actors for safe concurrency

In the previous section, we talked about writing concurrent code in the JVM and how it can be both error prone and also inefficient due to the overhead of obtaining instance locks. Since multi-threaded apps and multi-core machines are a way of life, we can't really ignore concurrency in the apps that we write on the JVM. Thankfully, Akka actors take the pain out of writing concurrency-aware components. In fact, it's so simple and consistent that I often forget how complicated the underlying concept used to be without Akka.

A lot of that simplicity stems from the way actor components communicate with each other via message passing. If component A (an actor) needs to use some functionality represented by component ...

Get Mastering Akka 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.