Skip to content
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

feat(eventLoop): the visibility of the shutdown flag for the event loop and optimizations for graceful shutdown #1796

Merged
merged 6 commits into from
Aug 23, 2024

Conversation

CLFutureX
Copy link
Contributor

The visibility of the shutdown flag for the event loop and optimizations for graceful shutdown

@CLFutureX CLFutureX changed the title feat(eventLoop): The visibility of the shutdown flag for the event loop and optimizations for graceful shutdown feat(eventLoop): the visibility of the shutdown flag for the event loop and optimizations for graceful shutdown Aug 14, 2024
@@ -79,6 +89,9 @@ public void execute(Runnable task) {

public CompletableFuture<Void> shutdownGracefully() {
shutdown = true;
if (!shutdownCf.isDone()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

To ensure concurrent safety, the operations of modifying shutdown and tasks need to be safeguarded by a lock. Similarly, other methods that use these two variables need to be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ensure concurrent safety, the operations of modifying shutdown and tasks need to be safeguarded by a lock. Similarly, other methods that use these two variables need to be modified.

Yes, perhaps we can modify the shutdown from a constant to an AtomicBoolean, utilizing CAS (Compare-And-Swap) to ensure concurrent safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ensure concurrent safety, the operations of modifying shutdown and tasks need to be safeguarded by a lock. Similarly, other methods that use these two variables need to be modified.

now, the tasks variable has also been modified.

@CLFutureX
Copy link
Contributor Author

@superhx Perhaps it should only adjust the visibility of the shutdown variable, without introducing a wakeup mechanism, because the worst-case scenario would only involve a wait of 100ms, which is generally acceptable for a graceful shutdown, What do you think?

import org.slf4j.Logger;

public class EventLoop extends Thread implements Executor {
private final Logger logger;
private BlockingQueue<Runnable> tasks;
private boolean shutdown = false;
private volatile boolean shutdown;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did not see when shutdown = true was set

@superhx
Copy link
Collaborator

superhx commented Aug 19, 2024

@superhx Perhaps it should only adjust the visibility of the shutdown variable, without introducing a wakeup mechanism, because the worst-case scenario would only involve a wait of 100ms, which is generally acceptable for a graceful shutdown, What do you think?

If it's not completed, I think it's ok to add the shutdown awake.

@CLFutureX CLFutureX requested a review from superhx August 19, 2024 07:23
@CLFutureX
Copy link
Contributor Author

@superhx hey, please take a look

@superhx superhx merged commit eae6e1a into AutoMQ:main Aug 23, 2024
6 checks passed
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.

2 participants