Hi. I followed the steps suggested by Guadalupe here and it still doesn't work. Can someone help me here?
I don't know exactly what should I return. I don't know if the problem is there or somewhere else.
Thanks.
package com.codegym.task.task27.task2707;
import java.util.concurrent.atomic.AtomicReference;
/*
Determining locking order
*/
public class Solution {
public void someMethodWithSynchronizedBlocks(Object obj1, Object obj2) {
synchronized (obj1) {
synchronized (obj2) {
System.out.println(obj1 + " " + obj2);
}
}
}
public static boolean isLockOrderNormal(final Solution solution, final Object o1, final Object o2) throws Exception {
final String[] strings = {null};
Thread t1 = new Thread() {
@Override
public void run() {
synchronized (o2) {
try {
Thread.currentThread().wait(1000);
} catch (InterruptedException e) {}
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
solution.someMethodWithSynchronizedBlocks(o1, o2);
}
};
Thread t3 = new Thread() {
@Override
public void run() {
synchronized (o1) {
strings[0] = "o1";
//Thread.sleep(100);
}
}
};
if(strings[0] == null)
return false;
return true;
}
public static void main(String[] args) throws Exception {
final Solution solution = new Solution();
final Object o1 = new Object();
final Object o2 = new Object();
System.out.println(isLockOrderNormal(solution, o1, o2));
}
}