Skip to content

Add Fork/Join design pattern (#3227)#3550

Open
SandhyaDevadiga wants to merge 2 commits into
iluwatar:masterfrom
SandhyaDevadiga:fork-join-pattern-3227
Open

Add Fork/Join design pattern (#3227)#3550
SandhyaDevadiga wants to merge 2 commits into
iluwatar:masterfrom
SandhyaDevadiga:fork-join-pattern-3227

Conversation

@SandhyaDevadiga

Copy link
Copy Markdown

Fixes #3227

What this PR does

Implements the Fork/Join concurrency pattern using a parallel array
summation example.

Files added

  • SumTask.java — RecursiveTask that splits the array and sums in parallel
  • ForkJoinSumCalculator.java — Wrapper class that manages the ForkJoinPool
  • App.java — Demo showing parallel sum of 10 million numbers
  • SumTaskTest.java — 6 unit tests for the recursive task
  • ForkJoinSumCalculatorTest.java — 5 unit tests for the calculator
  • README.md — Pattern explanation with examples and diagrams
  • pom.xml — Maven module configuration

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown

PR Summary

Implemented the Fork/Join concurrency pattern to sum a large array in parallel. Introduced a dedicated module fork-join containing App demo, ForkJoinSumCalculator wrapper, and SumTask RecursiveTask. Added unit tests for SumTask and ForkJoinSumCalculator, plus README documenting the pattern with examples and diagrams. Included Maven module (pom.xml) to package and run the demo.

Changes

File Summary
fork-join/README.md Explains the Fork/Join pattern with a Java example that sums a long array. Includes design rationale, a RecursiveTask-based SumTask, a ForkJoinSumCalculator wrapper, and an App demo. Also contains tests harness and a Maven module configuration.
fork-join/pom.xml Provides Maven module setup for the Fork-Join pattern project, including test dependency and mainClass for the assembled artifact.
fork-join/src/main/java/com/iluwatar/forkjoin/App.java Demo app that constructs 10M numbers, uses ForkJoinSumCalculator to compute their sum in parallel, and prints result, expected value, correctness, timing, and processor count.
fork-join/src/main/java/com/iluwatar/forkjoin/ForkJoinSumCalculator.java Wrapper around ForkJoinPool to execute a SumTask over an array; supports default common pool and custom parallelism; validates input.
fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java Recursive task that sums a long array, splitting by halves until the threshold; includes input validation for start vs end; uses fork/join for parallel computation.
fork-join/src/test/java/com/iluwatar/forkjoin/ForkJoinSumCalculatorTest.java JUnit tests for the calculator: zero for null/empty arrays, correct sums for small/large arrays, and custom parallelism.
fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java Tests for SumTask: direct sums for small arrays, large sums via fork/join, partial ranges, edge cases, million-element case, and exception when start > end.

autogenerated by presubmit.ai

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
  • 0f14977: Add fork-join pattern implementation
Files Processed (7)
  • fork-join/README.md (1 hunk)
  • fork-join/pom.xml (1 hunk)
  • fork-join/src/main/java/com/iluwatar/forkjoin/App.java (1 hunk)
  • fork-join/src/main/java/com/iluwatar/forkjoin/ForkJoinSumCalculator.java (1 hunk)
  • fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java (1 hunk)
  • fork-join/src/test/java/com/iluwatar/forkjoin/ForkJoinSumCalculatorTest.java (1 hunk)
  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java (1 hunk)
Actionable Comments (1)
  • fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java [50-55]

    possible bug: "Guard against invalid index range in SumTask"

Skipped Comments (2)
  • fork-join/src/main/java/com/iluwatar/forkjoin/App.java [28-28]

    performance: "High memory usage in demo due to full array materialization"

  • fork-join/pom.xml [41-41]

    maintainability: "Main class configuration in assembly plugin"

Comment thread fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.31%. Comparing base (74d2dbe) to head (f5fe108).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3550      +/-   ##
============================================
+ Coverage     83.24%   83.31%   +0.07%     
  Complexity     4025     4025              
============================================
  Files          1060     1060              
  Lines         14246    14246              
  Branches        686      686              
============================================
+ Hits          11859    11869      +10     
+ Misses         2100     2091       -9     
+ Partials        287      286       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: SandhyaDevadiga <sandhyadevadiga8197@gmail.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • f5fe108: Add input validation for start > end in SumTask

Signed-off-by: SandhyaDevadiga sandhyadevadiga8197@gmail.com

Files Processed (2)
  • fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java (1 hunk)
  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
  • fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java [37-44]

    possible bug: "Guard against end exceeding array length."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Fork/Join pattern

1 participant