Recap

We can’t avoid dealing with state, but we have three options:

  • Shared mutability

  • Isolated mutability

  • Pure immutability

Though we’re used to shared mutability, we should avoid it as much as possible. Eliminating shared mutable state is the easiest way to avoid synchronization woes. It takes us far more effort to pick these design approaches than to pick up a library or an API. It also requires us to step back and think through how we’d design applications.

We don’t want to compromise performance in order to preserve state. So, to design with immutability, we’ll need to use modern data structures that preserve state and at the same time provide great performance.

We discussed ways to deal with state in this chapter. Next, we’ll program concurrency ...

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.