CompletableFuture-对计算结果进行处理

深藏阁楼爱情的钟 2024-02-29 00:55 167阅读 0赞

99a19f203a864697bef5ec0c71371f42.png

  1. package com.nanjing.gulimall.zhouyimo.test;
  2. import java.util.concurrent.*;
  3. /**
  4. * @author zhou
  5. */
  6. public class CompletableFutureAPI2Demo {
  7. public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
  8. ExecutorService threadPool = Executors.newFixedThreadPool(3);
  9. CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
  10. try {
  11. TimeUnit.SECONDS.sleep(1);
  12. } catch (InterruptedException e) {
  13. e.printStackTrace();
  14. }
  15. System.out.println("111");
  16. return 1;
  17. }, threadPool).thenApply(f -> {
  18. System.out.println("222");
  19. return f + 2;
  20. }).thenApply(f -> {
  21. System.out.println(

发表评论

表情:
评论列表 (有 0 条评论,167人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Matlab:函数调用结果进行索引

    Matlab:对函数调用结果进行索引 在Matlab中,函数调用结果可以是一个向量、矩阵或多维数组。当我们需要访问特定元素或子集时,可以使用索引操作。索引允许我们按照位置来访