ExecutorService.submit(Task) vs CompletableFuture.supplyAsync(Task, Executor)

后端 未结 3 1174
盖世英雄少女心
盖世英雄少女心 2021-01-30 16:39

To run some stuff in parallel or asynchronously I can use either an ExecutorService: Future submit(Runnable task, T result); or the CompletableFu

3条回答
  •  不思量自难忘°
    2021-01-30 17:02

    CompletableFuture has rich features like chaining multiple futures, combining the futures, executing some action after future is executed (both synchronously as well as asynchronously), etc.

    However, CompletableFuture is no different than Future in terms of performance. Even when combine multiple instances of CompletableFuture (using .thenCombine and .join in the end), none of them get executed unless we call .get method and during this time, the invoking thread is blocked. I feel in terms of performance, this is not better than Future.

    Please let me know if I am missing some aspect of performance here.

提交回复
热议问题