Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Concurrent Patterns and Best Practices
  • Table Of Contents Toc
Concurrent Patterns and Best Practices

Concurrent Patterns and Best Practices

By : S. Khot
5 (1)
close
close
Concurrent Patterns and Best Practices

Concurrent Patterns and Best Practices

5 (1)
By: 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 (9 chapters)
close
close

Reader or writer locks


A readers–writer(RW) or shared-exclusivelock is a primitive synchronization that allows concurrent access for read-only operations, as well as  exclusive write operations. Multiple threads can read the data concurrently, but for writing or modifying the data, an exclusive lock is needed.

A writer has exclusive access for writing data. Till the current writer is done, other writers and readers will be blocked. There are many cases where data is read more often than it is written.

The following code shows how we use the locks to provide concurrent access to a Java Map<K, V>. The code synchronizes the internal map, using an RW lock:

public class RWMap<K, V> {
private final Map<K, V> map;
private final ReadWriteLock lock = new ReadWriteLock();
private final RWLock r = lock.getRdLock();
private final RWLock w = lock.getWrLock();

public RWMap(Map<K, V> map) {
this.map = map;
 }

public V put(K key, V value) throws InterruptedException {
w.lock();
try...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Concurrent Patterns and Best Practices
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon