/** * @author looper * @ **/ public class ProductorTest { public static void main(String[] args) { Clerk clerk = new Clerk(); //我要调用start 但是问题是,是属于tread下的方法,我要用子类来调用,所以 Productor productor = new Productor(clerk);//以为thrad(有参),里面有个runable的target直接执行的target的方法,所以 Customer customer = new Customer(clerk); productor.start(); customer.start(); } } class Clerk { //消费者消费方法 public void custest() { for (; ; ) { synchronized (this) { notify(); if (pronumber > 0) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("消费者消费" + "第" + pronumber + "个产品"); pronumber--;
多线程练习:生产者与消费者
最新推荐文章于 2024-05-27 15:09:44 发布