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();
}
}
}
输出(控制台的一部分)
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
为什么超过17个线程?
在我的测试用例中,我想要设置17个线程,我怎么做呢?如何理解forkjoinpool构造函数的并行性?
暂无答案!
目前还没有任何答案,快来回答吧!