Social Groups

According to the book Java Concurrency in Practice, there are different types of deadlocks such as Lock ordering deadlocks, Open call deadlocks and Resource deadlocks. All the examples in this note are inspired from the examples given in the book Java Concurrency in Practice.

Lock ordering deadlock is caused when using different order of acquiring locks when locking on multiple objects.

One simple scenario is when one thread executes some code synchronized on object1 and needs to execute code synchronized on object2 still holding the object1 lock. At the same time, a second thread executes some code synchronized to obejct2 and needs to execute code synchronized to object1. In simple terms, thread1 hold object1 lock and wait for object2 lock and thread 2 hold object 2 lock and wait for object 1 lock. Both the threads will keep on waiting for the resource held by the other without releasing the lock they hold.

The solution is also simple: either acquire only one lock at a time or when acquiring multiple locks, acquire them in same order, whenever feasible.

You are here

This is a personal technical blog where we share our understanding on various concepts and is neither an official page or documentation for the products described here, nor the official views of the companies we work with.

Keywords used in this website are trademarks of their respective owners. This website is not affiliated with Oracle™ and/or any of the JEE frameworks like Spring™, Struts™, Hibernate™ and JSF™.

All contents and materials are provided freely without any warranty or liability and nothing within the site should be considered as professional advice. In any doubt, please ask, and we will try to help you based on our knowledge. Please let us know if you feel anything is not right here (including any copyright violation) and we will act upon it as fast as we can.