@@ -0,0 +1,1140 @@
+package com.njust.test.learn;%0A%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0A/**%0A * Lock lock =new ReentrantLock();%0A * lock.lock();%0A * ...%0A * lock.unlock();%0A */%0Apublic class LockDemo%0A%7B%0A    public static void main(String%5B%5D args)%0A    %7B%0A        Printer printer = new Printer();%0A        %0A        new Thread(() -%3E %7B%0A            while (true)%0A            %7B%0A                printer.print(%221111111%22);%0A            %7D%0A        %7D).start();%0A        %0A        new Thread(() -%3E %7B%0A            while (true)%0A            %7B%0A                printer.print(%222222222%22);%0A            %7D%0A        %7D).start();%0A        %0A    %7D%0A    %0A    static class Printer%0A    %7B%0A        private Lock lock = new ReentrantLock();%0A        %0A        public void print(String name)%0A        %7B%0A            lock.lock();%0A            try%0A            %7B%0A                for (int i = 0; i %3C name.length(); i++)%0A                %7B%0A                    System.out.print(name.charAt(i));%0A                %7D%0A                System.out.println();%0A            %7D%0A            finally%0A            %7B%0A                lock.unlock();%0A            %7D%0A        %7D%0A        %0A    %7D%0A%7D%0A%0A%0A

Create LockDemo.java