Book Image

Concurrent Patterns and Best Practices

By : Atul S. Khot
Book Image

Concurrent Patterns and Best Practices

By: Atul S. Khot

Overview of this book

Selecting the correct concurrency architecture has a significant impact on the design and performance of your applications. Concurrent design patterns help you understand the different characteristics of parallel architecture to make your code faster and more efficient. This book will help Java developers take a hands-on approach to building scalable and distributed apps by following step-by-step explanations of essential concepts and practical examples. You’ll begin with basic concurrency concepts and delve into the patterns used for explicit locking, lock-free programming, futures, and actors. You’ll explore coding with multithreading design patterns, including master, slave, leader, follower, and map-reduce, and then move on to solve problems using synchronizer patterns. You'll even discover the rationale for these patterns in distributed and parallel applications, and understand how future composition, immutability, and the monadic flow help you create more robust code. By the end of the book, you’ll be able to use concurrent design patterns to build high performance applications confidently.
Table of Contents (14 chapters)

Chapter 5. Increasing the Concurrency

This chapter covers the various strategies for increasing the concurrency of data structures. We will look at the lock-free variants of stacks and queues. These lock-free versions use compare and swap (CAS) instead of explicit synchronization. This is a complex programming model, and as we will soon see, it requires extreme caution and deep analysis to make sure there are no subtle concurrency bugs, such as the ABA problem. The ABA problem is also described in this chapter, along with a strategy that can be used to deal with it effectively.

This chapter will also cover commonly used data structures, such as the following:

  • Concurrent stacks
  • Queues
  • Hash tables 

Finally, we will have a look athashtables, which are used to efficiently implement a setabstraction. A set holds unique elements and needs to cater for a fast lookup operation, whether a value is present in the set or not. First, we will look at the solution for this using explicit locking and thelock...