Java-Techie-jt / springboot-multithreading-example

46 stars 88 forks source link

How does task divide itself among the Thread .How completable future manages to distribute among multiple Threads #1

Open sidhantpant opened 4 years ago

mortezanaeimabadi commented 3 years ago

@sidhantpant CompletableFuture uses a common pool, which is created by the JVM, it is described in the ForkJoinPool API doc::

A static commonPool() is available and appropriate for most applications. The common pool is used by any ForkJoinTask that is not explicitly submitted to a specified pool. Using the common pool normally reduces resource usage (its threads are slowly reclaimed during periods of non-use, and reinstated upon subsequent use).

So CompletableFuture uses default commonPool containing threads to process async task and randomly it assigns the threads whenever completablyFuture.supplyAsync method or completableFuture.completedFuture is called.

Hope it helps.