O'Reilly logo

Programming Concurrency on the JVM by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required