Mixing Actors and STM

Actors nicely allow us to isolate mutable state. They work great if a problem can be divided into concurrent tasks that can run independently and communicate with each other asynchronously using messages. Actors, however, don’t provide a way to manage consensus across tasks. We may want the actions of two or more actors to all succeed or fail collectively; that is, either all of them succeed or all of them fail. Actors alone can’t do that for us, but we can achieve that by bringing STM into the mix. In this section, I assume you’ve read Chapter 6, Introduction to Software Transactional Memory and the discussions on actors and typed actors in this chapter.

The AccountService class that helped us transfer between two ...

Get Programming Concurrency on the JVM 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.