用wait与notify、notifyAll 实现生产者与消费者
关于多线程的生产者与消费者有多种方式实现。目前用学过的wait、notifyAll来实现。代码:
public class ThreadTest6 {
static class Storehouse {
private int capacity; // 仓库的容量
private int size; // 仓库的存货量
/**
* 初始化仓库的容量和实际存货量
*
* @param capacity
* @param size
*/
public Storehouse(int capacity, int size) {
super();
this.capacity = capacity;
this.size = size;
}
/**
* 生产指定数量的产品
*
* @param count
* 生产的产品数量
*/
public synchronized void