@@ -0,0 +1,3131 @@
+package com.mars.test.java;%0A%0Aimport com.google.common.cache.CacheBuilder;%0Aimport com.google.common.cache.CacheLoader;%0Aimport com.google.common.cache.LoadingCache;%0Aimport com.google.common.collect.Lists;%0Aimport lombok.extern.slf4j.Slf4j;%0Aimport org.junit.Test;%0A%0Aimport java.util.List;%0Aimport java.util.concurrent.Callable;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0Aimport static java.lang.Thread.sleep;%0A%0A/**%0A * Created by USER on 2017/2/21.%0A */%0A@Slf4j%0Apublic class TestConcurrent %7B%0A%0A    private static final LoadingCache%3CString, ReentrantLock%3E LockMap = CacheBuilder.newBuilder()%0A            .build(%0A                    new CacheLoader%3CString, ReentrantLock%3E() %7B%0A                        @Override%0A                        public ReentrantLock load(String key) throws Exception %7B%0A                            return new ReentrantLock();%0A                        %7D%0A                    %7D);%0A%0A    int count = 0;%0A%0A    @Test%0A    public void test1() throws ExecutionException, InterruptedException %7B%0A        ExecutorService executor = Executors.newFixedThreadPool(100);%0A        List%3CCallable%3CString%3E%3E task = Lists.newArrayList();%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A        task.add(getTask());%0A%0A        executor.invokeAny(task);%0A        log.info(%22waiting task%22);%0A        sleep(3000);%0A        log.info(%22shutdown %22);%0A        executor.shutdown();%0A        log.info(%22count =%22 + count);%0A    %7D%0A%0A    public Callable%3CString%3E getTask() %7B%0A        return new Callable%3CString%3E() %7B%0A            ReentrantLock lock = null;%0A%0A            @Override%0A            public String call() throws Exception %7B%0A                try %7B%0A                    lock = LockMap.get(%22aaa%22);%0A                    log.info(%22Locked: %22 + lock.isLocked());%0A                    log.info(%22Held by me: %22 + lock.isHeldByCurrentThread());%0A                    boolean acquired = lock.tryLock(100, TimeUnit.MINUTES);%0A                    log.info(%22Lock acquired: %22 + acquired);%0A                    count++;%0A                %7D catch (InterruptedException e) %7B%0A                    //%E5%8F%AF%E8%83%BD%E5%8F%91%E7%94%9F%E8%A6%81%E4%B8%8A%E9%94%81%E6%97%B6%E8%A2%AB%E9%94%81%E4%BA%86%0A                    log.error(%22Locked: %22 + lock.isLocked());%0A                    log.error(%22Held by me: %22 + lock.isHeldByCurrentThread());%0A                    log.info(%22Lock again !!!%22);%0A                    boolean acquired = lock.tryLock(100, TimeUnit.MINUTES);%0A                    log.info(%22Lock acquired: %22 + acquired);%0A                    count++;%0A                %7D catch (ExecutionException e) %7B%0A                    e.printStackTrace();%0A                %7D finally %7B%0A                    if (lock != null) %7B%0A                        lock.unlock();%0A                    %7D%0A                    log.info(%22unlock success%22);%0A                %7D%0A                return null;%0A            %7D%0A        %7D;%0A    %7D%0A%0A%0A%7D%0A

add test code