/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class DeadLock {
static class Friend {
this.name = name;
}
return this.name;
}
public synchronized void bow(Friend bower) {
//My Changes
System.
out.
format("%s: %s" + " has bowed to me!%n",
this.
name, bower.
getName()); //Line 17 //System.out.println(this.name + ": " + bower.getName() + " has bowed to me!"); //Line 18
bower.bowBack(this);
}
public synchronized void bowBack(Friend bower) {
System.
out.
format("%s: %s" + " has bowed back to me!%n",
this.
name, bower.
getName()); }
}
public static void main
(String[] args
) { final Friend alphonse = new Friend("Alphonse");
final Friend gaston = new Friend("Gaston");
@Override
public void run() {
alphonse.bow(gaston);
}
}).start();
@Override
public void run() {
gaston.bow(alphonse);
}
}).start();
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgRGVhZExvY2sgewpzdGF0aWMgY2xhc3MgRnJpZW5kIHsKICAgIHByaXZhdGUgZmluYWwgU3RyaW5nIG5hbWU7CgogICAgcHVibGljIEZyaWVuZChTdHJpbmcgbmFtZSkgewogICAgICAgIHRoaXMubmFtZSA9IG5hbWU7CiAgICB9CgogICAgcHVibGljIFN0cmluZyBnZXROYW1lKCkgewogICAgICAgIHJldHVybiB0aGlzLm5hbWU7CiAgICB9CgogICAgcHVibGljIHN5bmNocm9uaXplZCB2b2lkIGJvdyhGcmllbmQgYm93ZXIpIHsKICAgICAgICAvL015IENoYW5nZXMKICAgICAgICBTeXN0ZW0ub3V0LmZvcm1hdCgiJXM6ICVzIiArICIgaGFzIGJvd2VkIHRvIG1lISVuIiwgd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