public synchronized void set(String name,String sex){
if(flag){
try{this.wait();}catch(Exception e){}//1
}else{
this.name=name;
this.sex=sex;
}
flag=true;
this.notifyAll();//2
}
public synchronized void get(){
if(!flag){
try{this.wait();}catch(Exception e){};//3
}else{
System.out.println(Thread.currentThread().getName()+" "+name+"------->"+sex);
}
flag=false;
this.notifyAll();//4
}
}
2和4处处的notifyAll能唤醒哪的等待线程
2能唤醒3处的等待线程吗,4能唤醒3处的等待线程吗
|
|