DeadLockRunnable dlr = new DeadLockRunnable(true);
DeadLockRunnable dlr2 = new DeadLockRunnable(false);
//创建并开启两个线程
new Thread(dlr,"Chinese").start();
new Thread(dlr2,"America").start();
}
}
复制代码
困扰我好久,都不知道这是不是死锁,怎么看出来是不是死锁呢?求赐教,
部分执行结果如下:
Chinese-------Give me the knife!
America-------Give me the chopsticks!
America-------Give me the knife!
Chinese-------Give me the chopsticks!
Chinese-------Give me the knife!
America-------Give me the chopsticks!
America-------Give me the knife!
Chinese-------Give me the chopsticks!
America-------Give me the chopsticks!
Chinese-------Give me the knife!
Chinese-------Give me the chopsticks!
America-------Give me the knife!
America-------Give me the chopsticks!
Chinese-------Give me the knife!
America-------Give me the knife!
Chinese-------Give me the chopsticks!