王少雷 发表于 2013-1-21 15:13
纳尼?是不是啊。。。求代码。
class Res3{
public String name;
int count=1;
boolean flag=false;
public synchronized void set(){
while(flag){
try {wait();} catch (InterruptedException e){}
}
name="+烤鸭+-----"+count++;
System.out.println(Thread.currentThread().getName()+"生产--"+name);
notifyAll();
flag=true;
}
public synchronized void out(){
while(!flag){
try {wait();} catch (InterruptedException e){}
}
System.out.println(Thread.currentThread().getName()+"消费-----"+name);
notifyAll();
flag=false;
}
}
|