I'm going through Oracle docs for Deadlock .. I got this code
< Code> Public class deadlock {Fixed class friend {Private last string name; Public friend (string name) {this.name = name; } Public string getName () {this.name; } Public Synchronized Zero Bow (Make Friend) {System.out.format ("% s:% s" + "Hooked me!% N", this.name, bower.getName ()); Bower.bowBack (this); } Public Synchronized Zero Bow (Make Friend) {System.out.format ("% s:% s" + "Tilted me back!% N", this.name, bower.getName ()); }} Public static zero chief (string [] args) {last friend alphonse = new friend ("Alphonse"); Last friend Gaston = new friend ("Gaston"); New thread (new runleball) (public zero-zero) {alphonse.bow (Gaston);}}) Start (); New thread (new runnable () {public goes zero () {gastrin.bo (alphonse);}}) Start (); }}I failed to understand, in which case would the deadlock be?
I run this code, it works fine. So what should be a special event, when the deadlock will occur?
Suppose the bow is called first on the
alphance object, should it be the
alphanace object when
bower.bowBack (this) < / Code> is called the object on the brink? Because if you retain its lock, leave
No comments:
Post a Comment