在java中遵循死锁的正确示例吗?

时间:2014-06-18 14:13:31

标签: java multithreading

我希望使用两个线程的死锁情况...

public class ThreadDemo implements Runnable {

@Override
public void run() {

    System.out.println("b4 join" + Thread.currentThread().getName());

    try {
        Thread.currentThread().join();
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    System.out.println("after join" + Thread.currentThread().getName());

}

public static void main(String[] args) {

    Thread t = new Thread(new ThreadDemo());

    Thread t1 = new Thread(new ThreadDemo());

    t.start();

    t1.start();

}
}

   output

   b4 joinThread-0
   b4 joinThread-1

并且程序继续运行..每次执行第二次打印..我不确定这是否正确 僵局的例子与否?任何人都可以点亮这个..如果不正确的话,如何在java中使用两个线程死锁...(不能说新手到java但是对于线程我总是......)

0 个答案:

没有答案