数,onsumer(Storagestorage){this.storage=storage;}//线程run函数publicvoidrun(){consume(num);}//调用仓库Storage的生产函数publicvoidconsume(intnum){storage.consume(num);}//get/set方法publicintgetNum(){returnnum;}publicvoidsetNum(intnum){this.num=num;}publicStoragegetStorage(){returnstorage;}publicvoidsetStorage(Storagestorage){this.storage=storage;}}lassTest{publicstaticvoidmain(String[]args){//仓库对象Storagestorage=newStorage();//生产者对象Producerp1=newProducer(storage);Producerp2=newProducer(storage);Producerp3=newProducer(storage);Producerp4=newProducer(storage);Producerp5=newProducer(storage);Producerp6=newProducer(storage);Producerp7=newProducer(storage);//消费者对象Consumerc1=newConsumer(storage);Consumerc2=newConsumer(storage);Consumerc3=newConsumer(storage);//设置生产者产品生产数量p1.setNum(10);p2.setNum(10);p3.setNum(10);