Open
Description
Description
The Fork/Join pattern is a concurrency design approach that splits (“forks”) a large task into multiple smaller subtasks, processes these subtasks in parallel, and then recombines (“joins”) their results. In Java, this pattern is embodied by the ForkJoinPool
and RecursiveTask
/ RecursiveAction
classes within the java.util.concurrent
package. It’s particularly useful for CPU-intensive, divide-and-conquer problems where parallel processing can significantly reduce completion time.
Key Elements
- Divide-and-Conquer: Recursively split tasks into smaller chunks until reaching a manageable size.
- Parallel Processing: Distribute subtasks across a pool of worker threads (usually a
ForkJoinPool
). - Work Stealing: Idle threads “steal” tasks from busy threads’ queues to optimize utilization.
- RecursiveTask / RecursiveAction: Abstract classes for defining the task logic and splitting strategy (
RecursiveTask
returns a result,RecursiveAction
does not).
References
- Java Documentation for
ForkJoinPool
- Java Concurrency in Practice – Brian Goetz
- Java Design Patterns – Contribution Guidelines
Acceptance Criteria
- Create a new module or package named
fork-join
(or similar). - Demonstrate splitting a computationally intensive task into subtasks using
RecursiveTask
orRecursiveAction
. - Show how the results are joined together for a final outcome.
- Provide a README (or
.md
file) explaining the pattern with diagrams or code snippets. - Include tests verifying parallel execution and correctness of results.
- Ensure all code meets the repository style, naming conventions, and passes CI checks.
Metadata
Metadata
Assignees
Projects
Status
In Progress