@@ -0,0 +1,2772 @@
+package com.njust.test.learn;%0A%0Aimport java.util.concurrent.locks.Condition;%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0Apublic class LockConditionDemo%0A%7B%0A    private static final int COUNT = 50;%0A    %0A    public static void main(String%5B%5D args)%0A    %7B%0A        Manage manage = new Manage();%0A        %0A        new Thread(() -%3E %7B%0A            for (int i = 1; i %3C= COUNT; i++)%0A            %7B%0A                manage.subDo(i);%0A            %7D%0A        %7D).start();%0A        %0A        for (int i = 1; i %3C= COUNT; i++)%0A        %7B%0A            manage.mainDo(i);%0A        %7D%0A    %7D%0A    %0A    static class Manage%0A    %7B%0A        private static final int SUB_INTERVAL = 10;%0A        %0A        private static final int MAIN_INTERVAL = 50;%0A        %0A        private boolean subTurn = true;%0A        %0A        private Lock lock = new ReentrantLock();%0A        %0A        private Condition condition = lock.newCondition();%0A        %0A        public void subDo(int index)%0A        %7B%0A            lock.lock();%0A            %0A            try%0A            %7B%0A                while (!subTurn)%0A                %7B%0A                    try%0A                    %7B%0A                        //this.wait();%0A                        condition.await();%0A                    %7D%0A                    catch (Exception e)%0A                    %7B%0A                        e.printStackTrace();%0A                    %7D%0A                %7D%0A                %0A                for (int i = 1; i %3C= SUB_INTERVAL; i++)%0A                %7B%0A                    System.out.println(String.format(%22-%3E Sub%5B%25s%5D: %25s/%25s%22, index, i, SUB_INTERVAL));%0A                %7D%0A                %0A                subTurn = false;%0A                //this.notify();%0A                condition.signal();%0A            %7D%0A            finally%0A            %7B%0A                lock.unlock();%0A            %7D%0A            %0A        %7D%0A        %0A        public void mainDo(int index)%0A        %7B%0A            lock.lock();%0A            %0A            try%0A            %7B%0A                while (subTurn)%0A                %7B%0A                    try%0A                    %7B%0A                        //this.wait();%0A                        condition.await();%0A                    %7D%0A                    catch (Exception e)%0A                    %7B%0A                        e.printStackTrace();%0A                    %7D%0A                %7D%0A                %0A                for (int i = 1; i %3C= MAIN_INTERVAL; i++)%0A                %7B%0A                    System.out.println(String.format(%22=====%3E Main%5B%25s%5D: %25s/%25s%22, index, i, MAIN_INTERVAL));%0A                %7D%0A                %0A                subTurn = true;%0A                //this.notify();%0A                condition.signal();%0A            %7D%0A            finally%0A            %7B%0A                lock.unlock();%0A            %7D%0A            %0A        %7D%0A    %7D%0A%7D%0A%0A%0A

Create LockConditionDemo.java