Skip to content

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

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

Add Fork/Join design pattern (#3227)#3550
SandhyaDevadiga wants to merge 5 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

Implements the Fork/Join concurrency pattern using a parallel array summation example. Adds a standalone module fork-join with App, SumTask, ForkJoinSumCalculator, and unit tests, plus documentation.

Changes

File Summary
fork-join/README.md Added README explaining the Fork/Join pattern with a Java example that sums a large array, including concepts, usage, and sample output.
fork-join/pom.xml Introduced fork-join module pom with dependencies and build setup for tests and demo.
fork-join/src/main/java/com/iluwatar/forkjoin/App.java Demo app that constructs a 10 million element array and computes its sum via ForkJoinSumCalculator, outputting results and timing.
fork-join/src/main/java/com/iluwatar/forkjoin/ForkJoinSumCalculator.java Wrapper around ForkJoinPool to calculate sums; supports default common pool and custom parallelism; guards against null/empty input.
fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java RecursiveTask that divides work by halving the range; uses a threshold for direct sum; validates start/end and combines left/right results.
fork-join/src/test/java/com/iluwatar/forkjoin/ForkJoinSumCalculatorTest.java Unit tests for ForkJoinSumCalculator including null/empty arrays and large inputs; tests custom parallelism.
fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java Unit tests for SumTask covering small/large ranges, partial ranges, empty ranges, single element, million elements, and invalid start>end.
pom.xml Updated parent pom to include the new fork-join module in the build.

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

❌ Patch coverage is 72.09302% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.57%. Comparing base (74d2dbe) to head (f96697f).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
...-join/src/main/java/com/iluwatar/forkjoin/App.java 0.00% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3550      +/-   ##
============================================
+ Coverage     83.24%   83.57%   +0.33%     
- Complexity     4025     4225     +200     
============================================
  Files          1060     1110      +50     
  Lines         14246    14950     +704     
  Branches        686      708      +22     
============================================
+ Hits          11859    12495     +636     
- Misses         2100     2162      +62     
- Partials        287      293       +6     

☔ 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."

@iluwatar iluwatar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You need to add the new module to the parent pom.xml, otherwise CI does not build it

@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)
  • 0a403c3: Add fork-join module to parent pom.xml
Files Processed (1)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
  • pom.xml [141-141]

    maintainability: "Introduce a new module to the Maven reactor"

@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)
  • 4a9ef8f: Add missing assertThrows import in SumTaskTest
Files Processed (1)
  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java (1 hunk)
Actionable Comments (1)
  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [81-85]

    possible issue: "Constructor validation for invalid ranges"

Skipped Comments (6)
  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [13-22]

    readability: "Clarify end-exclusive semantics in tests"

  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [25-35]

    test: "Boundary test for threshold"

  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [39-46]

    readability: "End index semantics in documentation"

  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [50-57]

    maintainability: "Explicit empty-range validation"

  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [60-67]

    testing: "Single-element range behavior"

  • fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java [70-78]

    performance: "Performance considerations for large input"

Comment thread fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java

@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)
  • f96697f: Format fork-join code with Spotless
Files Processed (4)
  • 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/SumTaskTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
  • fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java [34-42]

    maintainability: "Guard against null input in SumTask constructor."

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

2 participants