0%

Book Description

A definitive guide to mastering and implementing concurrency patterns in your applications

Key Features

  • Build scalable apps with patterns in multithreading, synchronization, and functional programming
  • Explore the parallel programming and multithreading techniques to make the code run faster
  • Efficiently use the techniques outlined to build reliable applications

Book Description

Selecting the correct concurrency architecture has a significant impact on the design and performance of your applications. This book explains how to leverage the different characteristics of parallel architecture to make your code faster and more efficient.

To start with, you'll understand the basic concurrency concepts and explore patterns around explicit locking, lock free programming, futures & actors. Then, you'll get insights into different concurrency models and parallel algorithms and put them to practice in different scenarios to realize your application's true potential. We'll take you through multithreading design patterns, such as master, slave, leader, follower, map-reduce, and monitor, also helping you to learn hands-on coding using these patterns.

Once you've grasped all of this, you'll move on to solving problems using synchronizer patterns. You'll discover the rationale for these patterns in distributed & parallel applications, followed by studying how future composition, immutability and the monadic flow help create more robust code.

Toward the end of the book, you'll learn about the actor paradigm and actor patterns - the message passing concurrency paradigm.

What you will learn

  • Explore parallel architecture
  • Get acquainted with concurrency models
  • Internalize design themes by implementing multithreading patterns
  • Get insights into concurrent design patterns
  • Discover design principles behind many java threading abstractions
  • Work with functional concurrency patterns

Who this book is for

This is a must-have guide for developers who want to learn patterns to build scalable and high-performing apps. It's assumed that you already have a decent level of programming knowledge.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Concurrent Patterns and Best Practices
  3. Packt Upsell
    1. Why subscribe?
    2. packt.com
  4. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Concurrency – An Introduction
    1. Concurrency in a breeze
      1. The push for concurrency
        1. The MapReduce pattern
        2. Fault tolerance
      2. Time sharing 
      3. Two models for concurrent programming
    2. The message passing model
      1. Coordination and communication
      2. Flow control    
      3. Divide and conquer
      4. The concept of state
    3. The shared memory and shared state model
      1. Threads interleaving – the need for synchronization
      2. Race conditions and heisenbugs
      3. Correct memory visibility and happens-before
      4. Sharing, blocking, and fairness
      5. Asynchronous versus synchronous executions
      6. Java's nonblocking I/O
    4. Of patterns and paradigms
      1. Event-driven architecture 
      2. Reactive programming
      3. The actor paradigm
      4. Message brokers
      5. Software transactional memory
      6. Parallel collections 
    5. Summary
  7. A Taste of Some Concurrency Patterns
    1. A thread and its context
    2. Race conditions
      1. The monitor pattern
      2. Thread safety, correctness, and invariants
        1. Sequential consistency
        2. Visibility and final fields
      3. Double-checked locking
        1. Safe publication
        2. Initializing a demand holder pattern
      4. Explicit locking
        1. The hand-over-hand pattern
        2. Observations – is it correct?
      5. The producer/consumer pattern
        1. Spurious and lost wake-ups
      6. Comparing and swapping
    3. Summary 
  8. More Threading Patterns
    1. A bounded buffer
      1. Strategy pattern – client polls
      2. Strategy – taking over the polling and sleeping
      3. Strategy – using condition variables
    2. Reader or writer locks
      1. A reader-friendly RW lock
      2. A fair lock
    3. Counting semaphores
    4. Our own reentrant lock
    5. Countdown latch
      1. Implementing the countdown latch
    6. A cyclic barrier
    7. A future task
    8. Summary
  9. Thread Pools
    1. Thread pools 
      1. The command design pattern
      2. Counting words
      3. Another version
      4. The blocking queue
      5. Thread interruption semantics
    2. The fork-join pool
      1. Egrep – simple version
      2.  Why use a recursive task?
      3. Task parallelism
      4. Quicksort – using fork-join
        1. The ForkJoinQuicksortTask class  
        2. The copy-on-write theme
        3. In-place sorting
      5. The map-reduce theme 
    3. Work stealing
    4. Active objects
      1. Hiding and adapting
      2. Using a proxy
    5. Summary
  10. Increasing the Concurrency
    1. A lock-free stack
      1. Atomic references
      2. The stack implementation
    2. A lock-free FIFO queue
      1. How the flow works
      2. A lock-free queue
        1. Going lock-free
          1. The enque(v) method
          2. The deq() method
          3. Concurrent execution of the enque and deque methods
      3. The ABA problem
        1. Thread locals
        2. Pooling the free nodes      
        3. The atomic stamped reference
    3. Concurrent hashing
      1. The add(v) method
        1. The need to resize
      2. The contains(v) method
    4. The big lock approach 
      1. The resizing strategy
    5. The lock striping design pattern
    6. Summary
  11. Functional Concurrency Patterns
    1. Immutability
      1. Unmodifiable wrappers
      2. Persistent data structures
      3. Recursion and immutability
    2. Futures
      1. The apply method
        1. by-name parameters 
      2. Future – thread mapping
      3. Futures are asynchronous
      4. Blocking is bad 
      5. Functional composition
    3. Summary   
  12. Actors Patterns
    1. Message driven concurrency
      1. What is an actor?
        1. Let it crash
        2. Location transparency
        3. Actors are featherlight
      2. State encapsulation
      3. Where is the parallelism?
      4. Unhandled messages
      5. The become pattern
        1. Making the state immutable
      6. Let it crash - and recover
      7. Actor communication – the ask pattern
        1. Actors talking with each another
      8. Actor communication – the tell pattern
      9. The pipeTo pattern
    2. Summary
  13. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
13.59.180.111