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 6. Functional Concurrency Patterns

In the shared state model, problems start cropping up due to state being a mutable one. We learned how hard it becomes to correctly synchronize the thread state, keeping in mind the ability to work with correctness, starvation, and deadlocks.  

In this chapter, we will look at concurrency patterns, largely from a functional perspective. Functional Programming (FP) is a functional paradigm and a cornerstone of FP is immutability. We will use Scala to study this aspect. Immutable data structures use structural sharing and persistent data structures to ensure performance along with safety guarantees. 

We will also look at future abstraction as a representation of asynchronous computation. Asynchronous computations use threads in an optimum way. A Scala future is also a monad, offering composability.

Here is what this chapter will cover:

  • Immutability
  • Futures

This coverage should prepare us well to understand the actor paradigm, coming up in the next chapter...