@@ -0,0 +1,2602 @@
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.locks.Condition;%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0A/**%0A * product and customer%0A */%0Apublic class Hello %7B%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        BlockingList list = new BlockingList(10);%0A        ExecutorService executors = Executors.newCachedThreadPool();%0A%0A        executors.execute(new Productor(list));%0A        executors.execute(new Productor(list));%0A        executors.execute(new Customer(list));%0A        executors.execute(new Customer(list));%0A    %7D%0A%7D%0A%0Aclass Productor implements Runnable %7B%0A    private BlockingList list;%0A    private static int i = 0;%0A%0A    public Productor(BlockingList list) %7B%0A        this.list = list;%0A    %7D%0A%0A    public void run() %7B%0A        while (true) %7B%0A            list.add(%22hello world %22 + i++);%0A            System.out.println(%22-----------------add data ok%22);%0A            try %7B%0A                Thread.sleep(100);%0A            %7D%0A            catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A%0Aclass Customer implements Runnable %7B%0A    private BlockingList list;%0A%0A    public Customer(BlockingList list) %7B%0A        this.list = list;%0A    %7D%0A%0A    public void run() %7B%0A        while (true) %7B%0A            System.out.println(list.get());%0A        %7D%0A    %7D%0A%7D%0A%0Aclass BlockingList %7B%0A    private List%3CString%3E list = new ArrayList%3CString%3E();%0A    private int size = 0;%0A%0A    private Lock lock = new ReentrantLock();%0A    private Condition notFull  = lock.newCondition();%0A    private Condition notEmpty = lock.newCondition();%0A%0A    public BlockingList(int size) %7B%0A        this.size = size;%0A    %7D%0A%0A    public void add(String data) %7B%0A        lock.lock();%0A        try %7B%0A            while (list.size() %3E= size) %7B%0A                notFull.await();%0A            %7D%0A%0A            list.add(data);%0A            notEmpty.signal();%0A        %7D%0A        catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        finally %7B%0A            lock.unlock();%0A        %7D%0A    %7D%0A%0A    public String get() %7B%0A        String data = %22%22;%0A%0A        lock.lock();%0A        try %7B%0A            while (list.size() == 0) %7B%0A                notEmpty.await();%0A            %7D%0A%0A            data = list.remove(0);%0A            notFull.signal();%0A        %7D%0A        catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        finally %7B%0A            lock.unlock();%0A        %7D%0A%0A        return data;%0A    %7D%0A%7D

add java thread code