Deadlock detection in Java

后端 未结 16 1079
野的像风
野的像风 2020-11-28 20:21

Long time ago, I saved a sentence from a Java reference book: \"Java has no mechanism to handle deadlock. it won\'t even know deadlock occurred.\" (Head First Java 2nd E

16条回答
  •  天涯浪人
    2020-11-28 21:12

    you have to modify the code a little bit in the Deadlock Class

       Deadlock() {
        Therad t = new Thread(this); // modified
        t.start();
        System.out.println(); //any instruction to delay
        a.methodA(b);
    }
    

    Also the above code will not always cause a dead lock, only some times it may happen.

提交回复
热议问题