Skip to content

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

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?

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
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