CompletableFuture multi-threaded, single thread concurrent, or both?
As is explained in the javadoc
All async methods without an explicit Executor argument are performed using the ForkJoinPool.commonPool() (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run each task).
So a threadpool is used, either implicitly (unless you have a single core machine in which case the threads aren't pooled) or explicitly. In your case you would get to control the amount of threads used by using an explicit Executor
(e.g. ThreadPoolExecutor) with the amount of threads you want (most likely a lot less than 1000).
The calls cannot share a single thread (the calling thread), as Java doesn't have the capability for what people these days understand by asynchronous due to the popular async/await paradigm (i.e. the fictional "truly asynchronous" term - synchronous vs. asynchronous is independent of threads, but asynchronicity can be implemented with threads, as it is done in CompletableFuture
).
If you schedule your computation without specifying a thread-pool, the fork-join
common pool would be used, otherwise you can specify your own Executor
to supplyAsync
and choose a size that fits your need.