Skip to content

Implement Fork/Join pattern #3227

Open
Open
@iluwatar

Description

@iluwatar

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

  1. Java Documentation for ForkJoinPool
  2. Java Concurrency in Practice – Brian Goetz
  3. 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 or RecursiveAction.
  • 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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions