I have a doubt regarding Java Synchronization . I want to know if I have three Synchronized methods in my class and a thread acquires lock in one synchronized method other t
It is true and it does in this way. It is necessary as well to consistent the data of that object.
Suppose that this validation is not there and there is a variable x which is being manipulated by 2 different synchronized method xxx() and yyy().
so if Thread A gets lock of method xxx() which is manipulating x=5 and second thread B gets lock of method yyy() and manipulating x=-5 so in the end of method xxx() thread A is expecting x=5 but it will get x=0 that is wrong.
Thats why it is implemented in this way.