关于死锁程序不明白,高手能否解答一下?

xinqing6888 2004-02-10 11:20:21
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 ?
...全文
49 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧