首页 > 应用开发 > > Java- 请问如何使这段代码死锁?
public class MicroBlongNode {
public static void main(String[] args) {
final MicroBlongNode local = new MicroBlongNode("localhost:8888");
final MicroBlongNode other = new MicroBlongNode("127.0.0.1:8988");
final String first = "1";
final String second = "2";
new Thread(() -> local.propagate(first, other)).start();
new Thread(() -> other.propagate(second,local)).start();
}
private final String ident;
public MicroBlongNode(String ident) {
this.ident = ident;
}
public String getIdent() {
return ident;
}
public synchronized void propagate(String upd, MicroBlongNode backup) {
System.out.println(ident + ":recvd " + upd + "; backup:" + backup.getIdent());
this.confirmUpdate(this, upd);
}
public synchronized void confirmUpdate(MicroBlongNode other, String upd) {
System.out.println(ident + ":recvd confrim" + upd + "; from:" + other.getIdent());
}}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/625/viewspace-3118740/ ,如需转载,请注明出处,否则将追究法律责任。