Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 ForkJoin 的工作窃取而不是普通线程池的队列有什么好处?来自 ForkJoinPool 的“工作窃取”是否比从线程池队列中获取任务更好?不是偷东西吗?
ForkJoinPool 是为递归操作设计的。例如,这可能是像 MergeSort 这样的分而治之的算法。在这样的算法中,一个线程通常会等待孩子完成。
这就是“偷工减料”的用武之地。实际上有工作要做的人会从等待的线程中偷走工作。
如果您有固定数量的不会产生新线程的线程,您应该只使用普通的 ExecutorService 线程池。