Skip to Content
Software Architecture Design Patterns in Java
book

Software Architecture Design Patterns in Java

by Partha Kuchana
April 2004
Intermediate to advanced
520 pages
10h 10m
English
Auerbach Publications
Content preview from Software Architecture Design Patterns in Java

42 CONSISTENT LOCK ORDER

DESCRIPTION

During the discussion of the Monitor and the Critical Section patterns earlier, we have seen that when the synchronized keyword is used to ensure single-threaded execution of a code block, a thread needs to wait while trying to acquire the lock associated with the specified object. Consider a scenario where two threads hold locks on two different objects and each one is waiting for a lock on the object that is locked by the other thread. Both threads will be waiting forever and are said to be in a state of deadlock. In terms of implementation, this type of situation most often occurs due to an inconsistent order of locking objects. Let us consider the code segment in Listing 42.1 to illustrate how inconsistent ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Java

Hands-On Software Architecture with Java

Giuseppe Bonocore

Publisher Resources

ISBN: 9780203496213