@@ -0,0 +1,1953 @@
+package com.takin.emmet.concurrent;%0D%0A%0D%0Aimport java.util.concurrent.locks.Condition;%0D%0Aimport java.util.concurrent.locks.ReentrantLock;%0D%0A%0D%0Apublic class BoundedQueue%3CT%3E %7B%0D%0A    private final T%5B%5D array;%0D%0A%0D%0A    private int head;%0D%0A    private int tail;%0D%0A    private int count;%0D%0A%0D%0A    private final ReentrantLock lock = new ReentrantLock();%0D%0A%0D%0A    private Condition full = lock.newCondition();%0D%0A%0D%0A    private Condition empty = lock.newCondition();%0D%0A%0D%0A    public BoundedQueue(int size) %7B%0D%0A        array = (T%5B%5D) new Object%5Bsize%5D;%0D%0A    %7D%0D%0A%0D%0A    public void put(T item) throws InterruptedException %7B%0D%0A        //        lock.lock();%0D%0A        if (lock.tryLock()) %7B%0D%0A            try %7B%0D%0A                while (isFull()) %7B%0D%0A                    full.await();%0D%0A                %7D%0D%0A%0D%0A                array%5Btail%5D = item;%0D%0A                System.out.println(%22put-%22 + item);%0D%0A%0D%0A                if (++tail == array.length) %7B%0D%0A                    tail = 0;%0D%0A                %7D%0D%0A                count++;%0D%0A                empty.signal();%0D%0A            %7D catch (Exception e) %7B%0D%0A            %7D finally %7B%0D%0A                lock.unlock();%0D%0A            %7D%0D%0A        %7D%0D%0A%0D%0A    %7D%0D%0A%0D%0A    public T take() throws InterruptedException %7B%0D%0A        //        lock.lock();%0D%0A        if (lock.tryLock()) %7B%0D%0A            try %7B%0D%0A                while (isEmpty()) %7B%0D%0A                    empty.await();%0D%0A                %7D%0D%0A                Object obj = array%5Bhead%5D;%0D%0A                System.out.println(%22take-%22 + obj);%0D%0A                if (++head == array.length) %7B%0D%0A                    head = 0;%0D%0A                %7D%0D%0A                count--;%0D%0A                full.signal();%0D%0A                return (T) obj;%0D%0A            %7D catch (Exception e) %7B%0D%0A            %7D finally %7B%0D%0A                lock.unlock();%0D%0A            %7D%0D%0A        %7D%0D%0A%0D%0A        return null;%0D%0A    %7D%0D%0A%0D%0A    private boolean isFull() %7B%0D%0A        return count == array.length;%0D%0A    %7D%0D%0A%0D%0A    private boolean isEmpty() %7B%0D%0A        return count == 0;%0D%0A    %7D%0D%0A%7D%0D%0A

add boundedqueue