public synchronized int getSumOfVar1AndVar2() {
return var1 + var2;
}
public int getSumOfVar1AndVar2() {
synchronized (this) {
return var1 + var2;
}
}
Object obj = new Object();
public int getSumOfVar1AndVar2() {
synchronized (obj) {
return var1 + var2;
}
}
public int getSumOfVar1AndVar2() {
synchronized (Thread.currentThread()) {
return var1 + var2;
}
}
I sometimes feel lost and don't know for certain whether I get it.
Is it possible for multiple threads or objects synchronized with different mutexes to access the same synchronized block simultaneously?