package de.bvb; /** * 生产者消费者模式 * 通过 wait() 和 notify() 通信方法实现 * */ public class Test1 { public static void main(String[] args) { Godown godown = new Godown(50); for (int i = 0; i < 5; i++) { new ProducerThread(i * 10, godown).start(); new ConsumerThre
生产和消费者模式有很多种,现在介绍几种常见的方式 wait/notify实现生产和消费者模式 1.使用wait/notify实现生产和消费者模式: public class Depot { // 实际容量 private volatile int capacity = 0 ; // 最大容量 private static final int MAX_CAPACITY = 100 ; // 锁 private final Object lock = new Object() ; public De
package reentrantlock; import java.util.ArrayList; public class ProviderAndConsumerTest { static ProviderAndConsumer providerAndConsumer = new ProviderAndConsumer(); public static void main(String[] args) throws InterruptedException { // new Thread(n