Junior — Senior
Surely causing deadlock
livecode
Task condition
It is necessary to implement a class in which mutual thread blocking is guaranteed. To demonstrate this, two threads and two synchronized objects should be used. Each thread must acquire monitors in a different order, leading to a deadlock situation.
public class Deadlock {
private final Object monitorA = new Object();
private final Object monitorB = new Object();
public void run1() {
// ...
}
public void run2() {
// ...
}
public static void main(String[] args) {
// ...
}
}