Chapter 27

Minimizing Thread Blocking

Chapter 26 advocates the functional use of futures in a programming style that minimizes thread blocking. Over the years, much effort has been spent trying to avoid unnecessary thread blocking, often for performance reasons.1 This chapter provides a quick overview of some popular techniques that strive not to block threads and often abstain from using locks and other synchronizers.

1This process is still ongoing. On the JVM, in particular, see https://openjdk.org/jeps/425, known as Project Loom.

27.1 Atomic Operations

As a first illustration, consider the case of class java.util.concurrent.AtomicInteger, used in some earlier examples. It is straightforward to implement a thread-safe mutable integer in Java ...

Get Functional and Concurrent Programming: Core Concepts and Features 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.