Can a developer tell fork/join pool to create certain number of threads? If yes then is it guaranteed that those many number of threads will be created by pool?
Asked
Active
Viewed 2,033 times
0
-
Possible duplicate of [Custom thread pool in Java 8 parallel stream](https://stackoverflow.com/questions/21163108/custom-thread-pool-in-java-8-parallel-stream) – antak Mar 16 '18 at 04:31
-
"Depends entirely on" => no. Fork join pools can be created by hand, and there is an environment property that can override the *default* value (that is linked to the number of CPUs). So definitely no. On top of that, please note that the number of threads does not always match the number of threads created (threads die because of uncaught exceptions or the pool may time them out). So the wording of your questions touches on many different concepts, and in the end, it is not clear what you are asking. It may also help if we understood why you are asking. – GPI Jun 23 '20 at 12:41
2 Answers
1
Source : https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html
A ForkJoinPool is constructed with a given target parallelism level; by default, equal to the number of available processors. The pool attempts to maintain enough active (or available) threads by dynamically adding, suspending, or resuming internal worker threads, even if some tasks are stalled waiting to join others

Vicky
- 1,135
- 1
- 17
- 37
0
basically a fork join pool is ThreadPool which works on work-stealing algorithm. There are api to specify parallelism (max number of active threads - (0-2^15-1))
Specifying parallelism doesn't mean pool will create those many threads at start, but it will create threads if required when work is submitted to pool.

Gurwinder Singh
- 38,557
- 6
- 51
- 76

vermaji
- 539
- 2
- 10