Sobes.tech
Junior — Middle

How many threads does a parallel Stream use in the standard API configuration?

sobes.tech AI

Answer from AI

Parallel Stream in Java by default uses ForkJoinPool.commonPool(), which is created with a number of threads equal to the number of available processor cores (Runtime.getRuntime().availableProcessors()).

That is, the number of concurrently active threads is approximately equal to the number of CPU cores, allowing for efficient parallelization of tasks without excessive thread creation.