Java线程--CompletionService使用

原创:转载需注明原创地址 https://www.cnblogs.com/fanerwei222/p/11871911.html

Java线程--CompletionService使用

public static void main(String[] args) throws InterruptedException, ExecutionException {
    ExecutorService executorService = Executors.newFixedThreadPool(5);
    /**
     * 接口
     */
    CompletionService<Integer> completionService = new ExecutorCompletionService<Integer>(executorService);
    completionService.submit(() -> 1);
    /**
     * take()方法 取来 Future, 阻塞型的
     * Future.get()方法获取返回结果
     */
    completionService.take().get();
    /**
     * 接口
     */
    CompletionStage completionStage = null;
    /**
     * CompletionStage/Future 的实现类
     */
    CompletableFuture completableFuture = null;

}

猜你喜欢

转载自www.cnblogs.com/fanerwei222/p/11871911.html