What is an ad-hoc lock
synchronized (obj){
critical section
}
I understand this acquires the intrinsic lock for obj
.
public void transfer(int from, int to, int amount){
synchronized (lock){ // an ad-hoc lock
accounts[from] -= amount;
accounts[to] += amount;
}
System.out.println(. . .);
}
What does the synchronized (lock)
means in the above code.
What is an ad-hoc
lock?