Improve Blocking Operations of CompletableFuture

這陣子在研究CompletableFuture時,剛好看到一篇Oracle關於CompletableFuture如何使用才能有好效能的投影片。我在這裡做了些整理,分享給大家;如果有理解有問題或不足的地方,希望大家可以幫忙更正或補充。本篇圖片都來自於Reference中的投影片。本篇說到五個重點,前四點我會分別說明;第五點如字面上所說,ThreadPool本來就要根據需求而去使用,這裡我不特別探討。

  • Avoid transition task from one thread to another. It costs. link
  • Avoid blocking inside CompletableFuture chains. It costs. link
  • Carefully avoid transition task from one thread to another. It costs. link
  • It may be useful to build chain of actions before execution. link
  • Different ThreadPools show different performance.