How Can We Prevent a Deadlock in Java ?

To prevent a Deadlock from occurring at least one requirement for a deadlock has to be removed...

1 - Mutual exclusion : We can use optimistic locking to prevent mutual exclusion among resources.

2 - Resource holding : A thread has to release all its exclusive locks if it does not succeed in acquiring all exclusive locks for resources required.

3 - No preemption : We can use timeout period for an exclusive lock to get free after a given amount of time.

4 - Circular wait : We can check and ensure that circular wait does not occur, when all exclusive locks have been acquired by all the threads in the same sequence.



You May Interest

Why Did Oracle Release a New Version of Java Like Java 8 ?

What is Volatile Keyword in Java ?

What are the Situations in Which You Choose HashSet or TreeSet in ...

What are the Differences Between a Checked and Unchecked Exceptio ...

What is the Reason to Organize Classes and Interfaces in a Packag ...