Synchronized (instances) methods block an object, not a class.
alphonse.bow captures the alphabetical lock, and gaston.bow captures the gadon lock. When the “alphonse” stream is in the bow, it tries to grab the lock on the “gadon” on bower.bowBack. Likewise, the crap tries to capture an alpha lock.
Edit for clarity (hopefully):
Let the two threads Thread1 and Thread2 be called.
Thread1 launches alphonse.bow (gaston), where it grabs a lock on the alpha object, and Thread2 launches gaston.bow (alphonse) and grabs a lock on the gastant object.
In Thread1, when he tries to run bower.bowBack (this), where bower = gaston, the thread must first get a lock on the gadon.
While this continues, Thread2 is trying to do the same, with bower = alphonse. Thread1 has the lock that Thread2 requires, and vice versa, so a deadlock occurs.
As an aside, a dead end does not have to arise. If Thread1 can start and end before Thread2 has the ability to do this (for example, if something hangs in the main thread after Thread1 starts, but before Thread2 is created / started), then there will be a deadlock.
PH.
source share