主要是学习线程的用法,这个程序是简单的生产一个就取走一个。但是现在的程序好像
只能产不能去。球各位老师指正。
class Producer extends Thread{
private CubbyHole cubbyhole;
public Producer(CubbyHole c){
cubbyhole=c;
}
public void run(){
for(int i=0; i<5; i++){
cubbyhole.put(i);
System.out.println("Producer put:"+i);
try{
sleep((int)(Math.random()*100));
}
catch(InterruptedException e){
}
}
}
}
class Consumer extends Thread
q*****t 发帖数: 3
2
Put these three lines after the while loops:
seq=value;
available=true;
notify();
All the producers have never gone into the while loops
because the initial value of available is false. Customers
have never been notified.