Java 的 Fork/Join 与 ExecutorService - 何时使用哪个? [英] Java's Fork/Join vs ExecutorService - when to use which?
问题描述
我刚刚读完这篇文章:Java-5 ThreadPoolExecutor 相对于 Java-7 ForkJoinPool 的优势是什么? 并且觉得答案不够直接.
I just finished reading this post: What's the advantage of a Java-5 ThreadPoolExecutor over a Java-7 ForkJoinPool? and felt that the answer is not straight enough.
您能否用简单的语言和示例解释一下 Java 7 的 Fork-Join 框架与旧解决方案之间的权衡?
Can you explain in simple language and examples, what are the trade-offs between Java 7's Fork-Join framework and the older solutions?
我还阅读了 Google 关于该主题的排名第一的文章 Java 提示:何时使用 ForkJoinPool 与 ExecutorService 来自 javaworld.com 但文章没有回答标题问题何时,它主要讨论api差异......
I also read the Google's #1 hit on the topic Java Tip: When to use ForkJoinPool vs ExecutorService from javaworld.com but the article doesn't answer the title question when, it talks about api differences mostly ...
推荐答案
Fork-join 可以让你轻松执行分治任务,如果你想在 ExecutorService
.在实践中,ExecutorService
通常用于同时处理多个独立的请求(也称为事务),当你想加速一个连贯的工作时使用 fork-join.
Fork-join allows you to easily execute divide and conquer jobs, which have to be implemented manually if you want to execute it in ExecutorService
. In practice ExecutorService
is usually used to process many independent requests (aka transaction) concurrently, and fork-join when you want to accelerate one coherent job.
这篇关于Java 的 Fork/Join 与 ExecutorService - 何时使用哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!