This chapter covered some well-known patterns in concurrent programming. We focused on how to increase the concurrency of data structures, allowing multiple threads to make progress. Using implicit (or explicit) synchronization is a bottleneck, so we explored the alternatives.
We looked at lock-free data structures, using the compare and set (CAS) primitive provided by Java's concurrent library. We implemented a lock-free LIFO stack and then the more involved lock-free queue. We looked at and compared both variants of the queue: a lock-based queue and a lock-free queue.
Lock-free algorithms are more complex than their lock-synchronized counterparts. We looked at the
AtomicReference, the basis for these CAS-based algorithms. We also looked at the kind of situation where the ABA problem happens, and how the
AtomicStampedReference solves it.
Finally, we looked at hashing and how the lock striping concurrency pattern helps us to increase the concurrency for hash tables.
Armed with all...