This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
fix: Watchdog controls lifecycle of the future, not executor #1890
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Probably equivalent to
future.isCancelled()
.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.
I think isDone and isCancelled are equivalent. And both are slightly wrong for isTerminated. I think the strict definition of isTerminated is: not only has the task been unscheduled, but also that the last invocation stopped running.
Practically I dont think it matters too much. So if you want to take a shortcut and just use isDone, but document it.
Alternatively use a CountdownLatch where each run() is wrapped in an increment & decrement operation on the latch. awaitTermination can then block on the latch
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.
From the Javadoc for isDone:
It sounds like the last invocation would have stopped running. What makes you think otherwise?
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.
I think the cancellation of the future is only cancelling the scheduled tasks, if the
run()
method is already running and takes long time to complete, thenisDone()
could return true while therun()
is still running. I just reproduced this in my local as well.That being said, not sure if it matters that much in practice like Igor said, I don't know how long it takes for a typical
run()
to complete. Using a CountdownLatch is not enough in this case since it does not support increment, only decrement. So we may need something more if we want to fix it perfectly.