-
Notifications
You must be signed in to change notification settings - Fork 55
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
Make the Repeater class use a threads to execute the checks #493
Conversation
The Future returned by the Executor can be cancelled if it does not return a value after the required timeout.
hi @grkvlt looks good at an initial glance, but are there tests that could be added to demonstrate the improvement? |
I like the idea, very useful sometimes. Brooklyn already spins up a huge number of threads and this change will add even more even if not needed (tasks needs cancelling). Do you think each task will benefit from the change? If not, what if we provide a wrapper to |
46cb2d7
to
a9b945e
Compare
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.
Looking great, only concern is shutting down the executor if passed from the outside.
public ReferenceWithError<Boolean> runKeepingError() { | ||
Preconditions.checkState(body != null, "repeat() method has not been called to set the body"); |
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.
Any reason to remove the body != null check?
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.
Should have been changed to a checkNotNull()
call
|
||
Time.sleep(delayThisIteration); | ||
} finally { | ||
executor.shutdownNow(); |
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.
Don't shut down if passed from caller.
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.
Oops!
|
||
Future<?> call = executor.submit(body); | ||
try { | ||
call.get(delayThisIteration.toMilliseconds(), TimeUnit.MILLISECONDS); |
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 a separate time out is needed here, especially when used with backoff
, but happy to go with this.
f877b39
to
2003b4b
Compare
2003b4b
to
d6041d4
Compare
*/ | ||
public Repeater threaded(ExecutorService executor) { | ||
this.executor = executor; | ||
return this; |
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.
A bit on the pedantic side - can you add shutdown =false
here. Can imagine first calling threaded()
and passing the builder to another method only to add a custom executor using threaded(myExecutor)
. Good to merge after that.
@neykov have a look now, I updated the comments to be more explicit too |
@@ -0,0 +1,1072 @@ | |||
/* |
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.
Was this file committed by mistake? LGTM otherwise.
8f65875
to
2a3da72
Compare
Thanks for updates @grkvlt, merging. |
The Future returned by the Executor can be cancelled if it does not return a value after the required timeout.