public class Demo {
public static void main(String[] args) {
ForkJoinPool forkJoinPool = new ForkJoinPool(17);
for (int i = 0; i < 100; i++) {
forkJoinPool.execute(() -> {
System.out.println(Thread.currentThread().getName());
});
}
try {
TimeUnit.DAYS.sleep(1L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
output (part of console)
ForkJoinPool-1-worker-4
ForkJoinPool-1-worker-19
ForkJoinPool-1-worker-18
ForkJoinPool-1-worker-30
ForkJoinPool-1-worker-1
ForkJoinPool-1-worker-23
ForkJoinPool-1-worker-8
ForkJoinPool-1-worker-16
ForkJoinPool-1-worker-25
ForkJoinPool-1-worker-11
ForkJoinPool-1-worker-29
ForkJoinPool-1-worker-9
ForkJoinPool-1-worker-5
ForkJoinPool-1-worker-15
ForkJoinPool-1-worker-22
ForkJoinPool-1-worker-26
ForkJoinPool-1-worker-12
Why more than 17 threads?
In my test case, I want set 17 threads, how can I do that? How to understand the parallelism of forkjoinpool's constructor?