Avoiding deadlocks in Java

1
2
public class DeadlockDemo {
public static Object addLock = new Object();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Deadlocks can occur for many different reasons. There is no single recipe to avoid deadlocks. Normally deadlocks occur when one synchronized object is waiting for lock on resources locked by another synchronized object.

This program demonstrates a Deadlock.
This deadlock arises because both the threads are waiting for the resources which are grabbed by other thread. They both keep waiting and no one releases.

#java #deadlock #deadlocks #cesarnog #code #threads

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.