No, this will not lead to a deadlock.
To create a dead end, you need two Thread a and b and two resources x and y . If a contains a lock on x , but also requires a lock on y , but b contains a lock on y , and also requires a lock on x , then a deadlock occurs.
You have only one thing to lock here, this.sync , so there is no deadlock.
If methodB is entered when another thread calls methodA , it will wait until methodA releases the lock before continuing. If methodA is entered and another thread calls methodB , then it will wait until methodB releases the lock before continuing. Note that the fact that methodB calls methodA does not matter, since it has the same lock on this.sync .
source share