-
Notifications
You must be signed in to change notification settings - Fork 519
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
Using ScheduledExecutorService instead of Thread.sleep #154
Comments
Hi Darius! Could you please provide an example of detailed usage scenario? |
The use-case would be very similar to using the default sleeper. Only the implementation would not block thread. As you point out, since the public API is synchronous, this may be asking the impossible. The client code that calls the API would also need to be aware of the asynchronous approach, and will need to work with CompletableFuture, etc |
I had wondered some time ago whether |
@DariusX , thanks for the link, haven't seen it before |
I had a thought on whether the public API is currently synchronous: to the extent that the public API is declarative (i.e. incorporated via annotations), it isn't really specifically synchronous. Not sure where to go with that thought, but I'm putting it out there in case is sparks an idea. |
There is a public API in
|
Here's a prototype that works for Streaming types would be more of a challenge - you have to deal with the issue of whether to resume at the point where the exception occurred, or replay the whole result. Probably the latter is the best default. |
Dave, thank for prototype, this reusing of existing api looks very elegant for me. |
Yes, that bit will be hard. I’m not sure I want add new methods to existing interfaces yet, either. Also note that Spring has some abstractions already for scheduling and triggers. Another missing piece is intercepting callbacks from the user registered for the retry result (eg a |
It looks like I've solved a half of the problems, hope to come up with an extended prototype in a few weeks. Meanwhile, about support of java.util.concurrent.Future: because it has no "thenApply"-like notation, exception handling and retry scheduling for actual job can not be performed by worker right after previous attempt fails, i.e. invocation of "resultFuture.get()" is required to start even the first retry of actual job. That mixes sync and async approaches in a not very beautiful way, so I propose to not specially support java.util.concurrent.Future at all. (can show the details in my working copy) |
Currently have pretty small free time, so, decided at least to commit my old draft to discuss the approach in general. Here is the PR: #176 |
I get what you mean about I'll have a quick look at your backoff implementation. Sounds interesting. |
How about adding an implementation of Sleeper, based on ScheduledExecutorService that one could use if ThreadWaitSleeper is blocking too many threads?
The text was updated successfully, but these errors were encountered: