关于死锁程序不明白,高手能否解答一下?
import java.awt.*;
import java.io.*;
public class DD implements Runnable{
public static void main(String args[]){
DD dlk1=new DD();
DD dlk2=new DD();
Thread t1=new Thread(dlk1);//这个是什么意思?
Thread t2=new Thread(dlk2);
dlk1.grabIt=dlk2;//这个是什么意思?
dlk2.grabTt=dlk1;
t1.start();
t2.start();
System.out.println("Started");
try{
t1.join();
t2.join();
}
catch(InterruptedException e){
System.out.println("error occurred");
}
System.exit(0);
}
DD grabIt;//这个是什么意思?为什么还要有这个对象?
public synchronized void run(){
try{
Thead.sleep(1500);
}
catch(InterruptedException e){
System.out.println("error occurred");
}
grabIt.syncIt();
}
pulic synchronized void syncIt(){
try{
Thread.sleep(1500);
System.out.println("Sync");//为什么不显示sync
}
catch(InterruptedException e){
System.out.println("error occurred");
}
System.out.println("In the synchIt()method")
}
}
为什么输出的是Started ?