import java.util.concurrent.TimeUnit;
public class DeadLockTest {
public static Integer r1=1;
public static Integer r2=2;
public static Integer r3=1;
public static void main(String[] args) {
Thread t1=new Thread(new ThreadTest1());
t1.start();
Thread t2=new Thread(new ThreadTest2());
t2.start();
System.out.println("结果: "+(r1==r3));
}
}
class ThreadTest1 implements Runnable {
@Override
public void run() {
synchronized (DeadLockTest.r1){
try {
TimeUnit.SECONDS.sleep(3);
}catch (Exception e){
e.printStackTrace();
}
synchronized (DeadLockTest.r2){
System.out.println("ThreadTest1 start ...");
}
}
}
}
class ThreadTest2 implements Runnable{
@Override
public void run() {
synchronized (DeadLockTest.r2){
try {
TimeUnit.SECONDS.sleep(3);
}catch (Exception e){
e.printStackTrace();
}
synchronized (DeadLockTest.r1){
System.out.println("ThreadTest2 start ...");
}
}
}
}