多生产与一消费:操做栈

代码同“一辈子产与多消费”,区别在于测试类代码:java

public class Test {
    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        Produce produce1 = new Produce(myStack);
        Produce produce2 = new Produce(myStack);
        Produce produce3 = new Produce(myStack);
        Produce produce4 = new Produce(myStack);
        Produce produce5 = new Produce(myStack);
        Consumer consumer = new Consumer(myStack);
        ThreadProduce threadProduce1 = new ThreadProduce(produce1);
        ThreadProduce threadProduce2 = new ThreadProduce(produce2);
        ThreadProduce threadProduce3 = new ThreadProduce(produce3);
        ThreadProduce threadProduce4 = new ThreadProduce(produce4);
        ThreadProduce threadProduce5 = new ThreadProduce(produce5);
        threadProduce1.start();
        threadProduce2.start();
        threadProduce3.start();
        threadProduce4.start();
        threadProduce5.start();
        ThreadConsumer threadConsumer = new ThreadConsumer(consumer);
        threadConsumer.start();
    }
}
相关文章
相关标签/搜索