Skip to content

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

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

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

Introduces a new fork-join module that demonstrates the Fork/Join concurrency pattern by summing a large array in parallel. Adds SumTask, ForkJoinSumCalculator, App demo, unit tests, README, and Maven configuration; includes start/end validation in SumTask and integrates the module into the parent project.

Changes

File Summary
fork-join/README.md README documenting the Fork/Join pattern with explanation, examples, and diagrams.
fork-join/pom.xml Module POM for Fork/Join; sets artifactId, parent, dependencies, and build plugin for packaging.
fork-join/src/main/java/com/iluwatar/forkjoin/App.java Demo app that builds an array of 10 million numbers and sums via ForkJoinSumCalculator; prints results and performance data.
fork-join/src/main/java/com/iluwatar/forkjoin/ForkJoinSumCalculator.java Wrapper around ForkJoinPool to compute sum with SumTask; supports common pool and custom parallelism; handles null/empty input.
fork-join/src/main/java/com/iluwatar/forkjoin/SumTask.java RecursiveTask implementing the Fork/Join sum logic with a THRESHOLD; validates start/end; forks left and computes right; aggregates results.
fork-join/src/test/java/com/iluwatar/forkjoin/AppTest.java App usage test to ensure App.main runs without exceptions.
fork-join/src/test/java/com/iluwatar/forkjoin/ForkJoinSumCalculatorTest.java Tests for calculator: null/empty arrays, small/large sums, and custom parallelism.
fork-join/src/test/java/com/iluwatar/forkjoin/SumTaskTest.java Tests for SumTask: small/large ranges, partial ranges, empty range, single element, million elements, and exception on invalid range.
pom.xml Parent pom updated to include the fork-join module.

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 97.67442% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.63%. Comparing base (74d2dbe) to head (2a43036).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
...-join/src/main/java/com/iluwatar/forkjoin/App.java 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3550      +/-   ##
============================================
+ Coverage     83.24%   83.63%   +0.39%     
- Complexity     4025     4225     +200     
============================================
  Files          1060     1110      +50     
  Lines         14246    14950     +704     
  Branches        686      708      +22     
============================================
+ Hits          11859    12504     +645     
- Misses         2100     2154      +54     
- Partials        287      292       +5     

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

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)
  • 2a43036: Add AppTest to satisfy coverage requirements

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

Files Processed (1)
  • fork-join/src/test/java/com/iluwatar/forkjoin/AppTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • fork-join/src/test/java/com/iluwatar/forkjoin/AppTest.java [9-9]

    best_practice: "Clarify test intention with assertion"

  • fork-join/src/test/java/com/iluwatar/forkjoin/AppTest.java [7-10]

    best_practice: "Use assertDoesNotThrow to express non-exceptional execution"

@SandhyaDevadiga

Copy link
Copy Markdown
Author

All checks passing. Ready for review.

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