I don't know how to check the synchronized order for another method or the requirement of the task. Any advice will be helpful. Thanks a lot.
package com.codegym.task.task27.task2707;
import com.sun.org.apache.xpath.internal.functions.FuncFalse;
import java.util.concurrent.RecursiveTask;
/*
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 {
//do something here
Thread t = new Thread() {
public void run() {
synchronized (o1) {
synchronized (o2) {
}
}
}
};
solution.someMethodWithSynchronizedBlocks(o1, o2);
return false;
}
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));
}
}