Get Mystery Box with random crypto!

How to prevent Deadlocks? #locks #concurrency #I0I The locking | Java Tech News

How to prevent Deadlocks?
#locks #concurrency #I0I
The locking approach to thread safety is powerful, but (unlike confinement and immutability) it introduces blocking into the program. It's fairly easy to experience a deadlock when implementing a monitor pattern. Here're a few simple deadlock solutions:
Lock ordering — the ordering on the locks forces an ordering on the threads acquiring them, so there's no way to produce a cycle in the waiting-for graph.
Coarse-grained locking — use a single lock to guard many object instances, or even a whole subsystem of a program. Although it will prevent a large piece of code to run concurrently.
Lock Timeout — thread trying to obtain a lock will only try for so long before giving up by freeing all locks taken, wait for a random amount of time and then retry.
• Avoid the mutual exclusion or hold-and-wait for the shared resources.