The Java Fork-Join Pool: A Computation Model for Parallelism Flashcards
The _ in Java provides a powerful and efficient mechanism for parallelizing tasks, particularly those amenable to the “divide and conquer” approach.
Fork-Join framework
Its internal workings are designed to maximize performance and scalability by leveraging multi-core processors and a sophisticated work-stealing algorithm.
The fork-join pool supports a style of parallel programming that solves problems by _.
Solve (problem)
—if problem is small enough
——solve problem directly (sequential algorithm)
—else
——split problem into independent parts
——fork new sub-tasks to solve each part
——join all sub-tasks
——compose result from sub-results
divide and conquer
Java Fork-Join Pool Computation Model
1. Splitting a task into sub-tasks creates the tasks by using the fork()ing
2. Solving the sub-tasks in parallel
▪ Implemented by fork-join framework
▪ Java execution environment,
▪ Operating System
▪ Hardware
▪ Subtask can run parallel on different cores
▪ can run concurrently in different threads on a single-core
3. Waiting for them to complete
4. Merging the results can use calls to join() to merge all sub-task results together
Noted
_ implements an Executor Service.
Fork-Join Pool
_ is the basis for Java Executor framework subclasses.
Executor Service
_ is the other implementation of ExecutorService executes in runnable or callable.
AbstractExecutorService
The purpose of ForkJoinPool in contrast, is to
execute _.
ForkJoinTasks
Each _ has its own stack, registers, etc.
worker thread
Fork() does not run the task immediately, but instead places it on the _.
work queue
Unlike thread.join(), ForkJoinTasks.join() doesn’t simply _ the calling thread. It uses _ to thread to run tasks.
block, workers
When a worker thread encounters a _, it processes other tasks until it notices that target sub-task is done.
join()
Programs rarely use the ForkJoinTask class directly, but instead, extend one of its subclasses & override compute() Three Classes:
* RecursiveAction – used for computations that do not return results
* RecursiveTask – used for computations that do return results
* CountedCompleter – used for computations in which completed actions trigger other actions
Noted
ForkJoinPool enables a _ client to process ForkJoinTasks
non-ForkJoinTask
The client inserts new tasks onto a shared queue used to fee “work stealing queues managed by worker threads.
The goal of “work-stealing” is to maximize _.
processor core utilization
Each worker thread in a forkjoinpool runs in a _ that scans from sub-tasks to execute.
loop
- The goal for the work thread is to keep as busy as possible.
- The worker threads only block waiting for work if no (sub-) tasks are available to run therefore, the working thread checks multi-input sources for (sub-) tasks to execute.