Strategies for Effective Concurrency

On one hand, we want to ensure consistency and accuracy when using concurrency. On the other hand, we want to ensure we’re getting as much performance as possible on the given hardware. In this chapter, we looked at ways to meet both these goals.

We can easily avoid race conditions or consistency issues once we fully eliminate shared mutable state. When threads don’t compete to access mutable data, there’s no issue of visibility and crossing the memory barrier. We also don’t have to worry about controlling the execution sequence of threads; since they don’t compete, there are no mutually exclusive sections to safeguard in code.

Provide shared immutability where possible. Otherwise, follow isolated mutability—ensure ...

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.