Chapter 23
Common Synchronizers
Concurrency libraries often contain extensive tools for inter-thread synchronization. This chapter describes some of the most common synchronizers, along with typical usage patterns.
23.1 Locks
The best-known synchronizer is the exclusive lock, which we have already seen in several code illustrations in previous chapters. What was used through synchronized
is the so-called intrinsic locking mechanism of the JVM—every object can be used as a lock. The Java standard library defines three types of locks in addition to intrinsic locks. Two forms are of particular interest and are briefly discussed in this section. The third, StampedLock
, is rarely used and reserved for advanced usage.
First is the class ReentrantLock ...
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.