Thread vs CompletableFuture

后端 未结 3 848
無奈伤痛
無奈伤痛 2021-01-31 09:56

What is the advantage of passing code directly to thread vs using CompletableFuture instead?

Thread thread = new Thread(() -> {do something});
thread.start()         


        
3条回答
  •  伪装坚强ぢ
    2021-01-31 10:09

    CompletableFuture is a promise which uses default ForkJoinPool (thread pool of size equal to number of CPU's) unless provided with another ThreadPool. A thread pool will contain n or more number of Thread.

提交回复
热议问题