Coordinating Actors
The real benefit and fun is when actors coordinate with each other to solve problems. To make use of concurrency, we’d divide a problem into parts. Different actors may take on different parts, and we need to coordinate the communication between them. That’s what we’ll learn here by using the file size program as an example.
In Coordinating Threads, we wrote a program to find the total size of all files under a given directory. In that we launched 100 threads, each of which explored different subdirectories. We then totaled the sizes that were computed asynchronously. We saw different approaches to doing that, with AtomicLongs and queues. We can sum up those approaches as hard work to deal with shared mutability.
We can ...
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.