ExecutorService is an Executor that provides methods to manage the progress-tracking and termination of asynchronous tasks. Prior to the introduction of java.util.concurrent, Java developers relied on third-party libraries or wrote their own classes to manage concurrency in their programs.
Fork/Join, introduced in Java 7, isn't intended to replace or compete with the existing concurrency utility classes; instead it updates and completes them. Fork/Join addresses the need for divide-and-conquer, or recursive task-processing in Java programs
Fork/Join's logic is very simple: (1) separate (fork) each large task into smaller tasks; (2) process each task in a separate thread (separating those into even smaller tasks if necessary); (3) join the results.
For this example we'll use a
ForkJoinPool
"backed" by 64 threads. I say backed because ForkJoinTask
s are lighter than threads. In Fork/Join, a large number of tasks can be hosted by a smaller number of threads.Read full article from Java Tip: When to use ForkJoinPool vs ExecutorService | JavaWorld
No comments:
Post a Comment