private static final Object A = new Object();
private static final Object B = new Object();
public static void methodA() {
synchronized (A) {
//Do Job
}
}
public static void methodB() {
synchronized (B) {
//Do Job
}
}
public static void methodSync() {
synchronized (A) {
synchronized (B) {
//Do Job
}
}
}
I guess that will work. Good luck.
P.S. You can replace synchronized with ReadWriteLock (acquiring the read lock in methods A & B and the write lock in methodSync. If that's worth doing is if you want two callers in methodA at the same time.