package pcmodel;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.*;

/**
 * Created by 李恒名 on 2017/6/8.
 *
 *  生产者消费者模型测试
 */
public class Tester {
    public static void main(String[] args) {
        test1();
    }

    //测试wait、notify实现
    public static void test1(){
        List<Product> buffer = new LinkedList<Product>();
        ExecutorService es = Executors.newFixedThreadPool(5);
        //两个生产者
        es.execute(new Producer(buffer));
        es.execute(new Producer(buffer));
        //三个消费者
        Consumer consumer = new Consumer(buffer);
        es.execute(new Consumer(buffer));
        es.execute(new Consumer(buffer));
        es.execute(new Consumer(buffer));

        es.shutdown();

    }
    //测试blocked queue实现
    public static void test2(){
        BlockingQueue<Product> buffer = new LinkedBlockingQueue<Product>(10);
        ExecutorService es = Executors.newFixedThreadPool(5);
        //两个生产者
        es.execute(new ProducerBlockedQueueImpl(buffer));
        es.execute(new ProducerBlockedQueueImpl(buffer));
        //三个消费者
        es.execute(new ConsumerBlockedQueueImpl(buffer));
        es.execute(new ConsumerBlockedQueueImpl(buffer));
        es.execute(new ConsumerBlockedQueueImpl(buffer));

        es.shutdown();
    }
}

@@ -732,16 +732,549 @@
 tdown();
+%0A        /**%0A         %E8%BE%93%E5%87%BA%EF%BC%9A%0A         ...%0A         %E7%94%9F%E4%BA%A7%E8%80%85%5Bpool-1-thread-2%5D%E7%94%9F%E4%BA%A7%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E7%94%9F%E4%BA%A7%E8%80%85%5Bpool-1-thread-2%5D%E7%94%9F%E4%BA%A7%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E6%B6%88%E8%B4%B9%E8%80%85%5Bpool-1-thread-5%5D%E6%B6%88%E8%B4%B9%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E6%B6%88%E8%B4%B9%E8%80%85%5Bpool-1-thread-5%5D%E6%B6%88%E8%B4%B9%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E6%B6%88%E8%B4%B9%E8%80%85%5Bpool-1-thread-5%5D%E6%B6%88%E8%B4%B9%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E6%B6%88%E8%B4%B9%E8%80%85%5Bpool-1-thread-5%5D%E6%B6%88%E8%B4%B9%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E6%B6%88%E8%B4%B9%E8%80%85%5Bpool-1-thread-5%5D%E6%B6%88%E8%B4%B9%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E7%94%9F%E4%BA%A7%E8%80%85%5Bpool-1-thread-1%5D%E7%94%9F%E4%BA%A7%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E6%B6%88%E8%B4%B9%E8%80%85%5Bpool-1-thread-4%5D%E6%B6%88%E8%B4%B9%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         %E7%94%9F%E4%BA%A7%E8%80%85%5Bpool-1-thread-2%5D%E7%94%9F%E4%BA%A7%E4%BA%86%E4%B8%80%E4%B8%AA%E4%BA%A7%E5%93%81%EF%BC%9AiPhone %E6%89%8B%E6%9C%BA%0A         ...%0A         */
 %0A%0A    %7D%0A

add > 添加运行结果注释