Is there any difference between the two :
public void synchronized func() {
}
and
public void func() {
synchronized(this) {
}
}
I understand in the first case the whole function func
is synchronized and in the second case only a part of the function's code is synchronized. But does it make a difference ? I mean instructions are always executed one after the another. It won't be that if a thread is unable to acquire the lock as it reaches the synchronized block, it will start the operations after the synchronized block !
Is there any functional difference at all or it is just a good practice ?