@@ -0,0 +1,1732 @@
+package com.gochinatv.cdn.api.jdk.concurrent;%0D%0A%0D%0Aimport java.util.concurrent.Callable;%0D%0Aimport java.util.concurrent.CompletionService;%0D%0Aimport java.util.concurrent.ExecutionException;%0D%0Aimport java.util.concurrent.ExecutorCompletionService;%0D%0Aimport java.util.concurrent.ExecutorService;%0D%0Aimport java.util.concurrent.Executors;%0D%0Aimport java.util.concurrent.TimeUnit;%0D%0A%0D%0Aimport org.apache.commons.lang3.RandomUtils;%0D%0Aimport org.junit.Test;%0D%0A%0D%0A/**%0D%0A * http://blog.csdn.net/u011734144/article/details/52351841%0D%0A * @author jacktomcat%0D%0A *%0D%0A */%0D%0Apublic class FutureTest %7B%0D%0A%0D%0A%09%0D%0A%09ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);%0D%0A%09CompletionService%3CString%3E completionService = new ExecutorCompletionService%3C%3E(fixedThreadPool);%0D%0A%09%0D%0A%09@Test%0D%0A%09public void test()%7B%0D%0A%09    %0D%0A%09%09String%5B%5D names = new String%5B100%5D;%0D%0A%09%09for(int i=0;i%3C100;i++)%7B%0D%0A%09%09%09names%5Bi%5D=%22names%22+i;%0D%0A%09%09%7D%0D%0A%09    for(int i=0;i%3Cnames.length;i++)%7B%0D%0A%09    %09completionService.submit(expectDbAsync(names%5Bi%5D));%0D%0A%09    %7D%0D%0A%09%09%0D%0A%09    for(int i=0;i%3Cnames.length;i++)%7B%0D%0A%09    %09try %7B%0D%0A%09%09%09%09String string = completionService.take().get();//%E6%97%A0%E5%BA%8F,%E5%85%88%E8%AE%A1%E7%AE%97%E5%AE%8C%E5%85%88%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%0D%0A%09%09%09%09System.out.println(string);%0D%0A%09%09%09%7D catch (InterruptedException %7C ExecutionException e) %7B%0D%0A%09%09%09%09e.printStackTrace();%0D%0A%09%09%09%7D%0D%0A%09    %7D%0D%0A%09    %0D%0A%09    %0D%0A%09    %0D%0A%09    fixedThreadPool.shutdown();%0D%0A%09    try %7B%0D%0A%09%09%09fixedThreadPool.awaitTermination(5, TimeUnit.MINUTES);%0D%0A%09%09%7D catch (InterruptedException e) %7B%0D%0A%09%09%09e.printStackTrace();%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D%0A%09public Callable%3CString%3E expectDbAsync(String name)%7B%0D%0A%09%09Callable%3CString%3E task = new Callable%3CString%3E() %7B%0D%0A%0D%0A%09%09%09@Override%0D%0A%09%09%09public String call() throws Exception %7B%0D%0A%09%09%09%09int random = RandomUtils.nextInt(1, 300);%0D%0A%09%09%09%09Thread.sleep(random);%0D%0A%09%09%09%09return name;%0D%0A%09%09%09%7D%0D%0A%09%09%7D;%0D%0A%09%09return task;%0D%0A%09%7D%0D%0A%09%0D%0A%7D%0D%0A

add FutureTest support