????Lock ??????????? synchronized ???????????????????????????????????????????????????в??????????????????????? Condition ????
????public class Storage<T> {
????// ????洢??
????private final int MAX_SIZE = 1000;
????private int storageSize = 100;
????private Object[] data;
????private int top = 0;
????private Lock lock = new ReentrantLock();
????private Condition producerCon = lock.newCondition();
????private Condition consumerCon = lock.newCondition();
????public Storage(int size) {
????size = size <= 0 ? storageSize : size;
????size = size > this.MAX_SIZE ? this.MAX_SIZE : size;
????this.storageSize = size;
????data = new Object[this.storageSize];
????}
????public int getStorageSize() {
????return storageSize;
????}
????public T pop() throws InterruptedException {
????T t = null;
????lock.lock();
????try {
????while (top == 0) {
????//????????
????consumerCon.await();
????}
????top--;
????t = (T) data[top];
????//??????????
????producerCon.signal();
????} finally {
????lock.unlock();
????}
????return t;
????}
????public void push(T t) throws InterruptedException {
????lock.lock();
????try {
????while (top == storageSize) {
????//????????
????producerCon.await();
????}
????data[top++] = t;
????//??????????
????consumerCon.signal();
????} finally {
????lock.unlock();
????}
????}
????}