public class ProducerConsumer {
public static void main(String args[]){
SyncStack ss = new SyncStack();//
Producer p = new Producer(ss) ; //new生产者对象
Consumer c = new Consumer(ss) ;//new消费者对象
new Thread (p).start();
new Thread (p).start();
new Thread (p).start();
new Thread (c).start();
}
}
class WoTou {//建立对象WoTou
int id ;
WoTou(int id){
this.id = id;
}
public String toString(){
return "WoTou: " +id;//返回 WoTou的id ;
}
}
class SyncStack{
int index = 0 ;
WoTou arrWT[] = new WoTou[6];//定义数组arrWT[]的类型为 WoTou ;长度为 6 ;
public class ProducerConsumer {
public static void main(String args[]){
SyncStack ss = new SyncStack();//
Producer p = new Producer(ss) ; //new生产者对象
Consumer c = new Consumer(ss) ;//new消费者对象
new Thread (p).start();
new Thread (p).start();
new Thread (p).start();
new Thread (c).start();
}
}
class WoTou {//建立对象WoTou
int id ;
WoTou(int id){
this.id = id;
}
public String toString(){
return "WoTou: " +id;//返回 WoTou的id ;
}
}
class SyncStack{
int index = 0 ;
WoTou arrWT[] = new WoTou[6];//定义数组arrWT[]的类型为 WoTou ;长度为 6 ;