@@ -0,0 +1,1279 @@
+package com.hzh.corejava.concurrent.lock;%0A%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0A/**%0A * Created by huangzehai on 2017/4/5.%0A */%0Apublic class ReentrantCounter %7B%0A    private Lock lock = new ReentrantLock();%0A    private int value = 0;%0A%0A    public void increase() %7B%0A        lock.lock();%0A        value++;%0A        logging();%0A        lock.unlock();%0A    %7D%0A%0A    private void logging() %7B%0A        lock.lock();%0A        System.out.println(%22Current value is %22 + value);%0A        lock.unlock();%0A    %7D%0A%0A    public int getValue() %7B%0A        return value;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        ReentrantCounter counter = new ReentrantCounter();%0A%0A        ExecutorService pool = Executors.newFixedThreadPool(2);%0A        for (int i = 0; i %3C 10; i++) %7B%0A            pool.submit(() -%3E %7B%0A                counter.increase();%0A            %7D);%0A        %7D%0A%0A        pool.shutdown();%0A%0A        try %7B%0A            pool.awaitTermination(10, TimeUnit.SECONDS);%0A            System.out.println(%22Total is %22 + counter.getValue());%0A        %7D catch (InterruptedException e) %7B%0A            System.out.println(e);%0A        %7D%0A%0A    %7D%0A%7D%0A

Add reentrant counter example