-
-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Join Pattern #3172
base: master
Are you sure you want to change the base?
Added Join Pattern #3172
Conversation
PR SummaryThis PR implements the Join design pattern, enabling synchronization of multiple threads. All Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
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 (7)
Files Processed (11)
- join/README.md (1 hunk)
- join/etc/JoinPatternFlowDiagram.png (0 hunks)
- join/etc/java-join-method.png (0 hunks)
- join/etc/join.urm.puml (1 hunk)
- join/pom.xml (1 hunk)
- join/src/main/java/com/iluwatar/join/DemoThread.java (1 hunk)
- join/src/main/java/com/iluwatar/join/DependentThread.java (1 hunk)
- join/src/main/java/com/iluwatar/join/JoinPattern.java (1 hunk)
- join/src/main/java/com/iluwatar/join/JoinPatternDemo.java (1 hunk)
- join/src/test/java/com/iluwatar/join/JoinPatternTest.java (1 hunk)
- pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
package com.iluwatar.join; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** Here main thread will execute after completion of 4 demo threads | ||
* main thread will continue when CountDownLatch count becomes 0 | ||
* CountDownLatch will start with count 4 and 4 demo threads will decrease it by 1 | ||
* everytime when they will finish . | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The programmatic example in README.md
should be minimalistic. It doesn't have to compile. The main purpose is to explain the reader how the pattern works using code snippets.
try { | ||
previous.join(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log to Slf4j log, not to console, e.g.
log.error("An error occurred: {}", e.getMessage(), e);
/** Here main thread will execute after completion of 4 demo threads | ||
* main thread will continue when CountDownLatch count becomes 0 | ||
* CountDownLatch will start with count 4 and 4 demo threads will decrease it by 1 | ||
* everytime when they will finish . | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain the pattern briefly. After that explain how the code example implements it. Add comments to the code where necessary. Remember, this is material for studying design patterns.
Implemented the join design pattern that allows multiple threads to be synchronized such that all DemoThreads must complete before any DependentThreads can proceed .
Close #70