
package com.nanjing.gulimall.zhouyimo.test;
import java.util.concurrent.*;
/**
* @author zhou
*/
public class CompletableFutureAPI2Demo {
public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
ExecutorService threadPool = Executors.newFixedThreadPool(3);
CompletableFuture.supplyAsync(() -> {
return 1;
}, threadPool).thenApply(f -> {
return f + 2;
}).thenApply(f -> {
return f + 3;
}).thenAccept(r -> {
System.out.println(r);//6
});
System.out.println(Thread.currentThread().getName() + "------主线程先去做其他事情");
threadPool.shutdown();
}
}
6
main------主线程先去做其他事情
还没有评论,来说两句吧...