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

Restore the interrupted thread status in the provided backoff policies #386

Closed
mlichtblau opened this issue Oct 16, 2023 · 2 comments
Closed

Comments

@mlichtblau
Copy link
Contributor

It is good practice to restore the interrupted flag of the current thread when InterruptedException cannot be thrown.

From Java Concurrency in Practice1:

Sometimes you cannot throw InterruptedException, for instance when your code is part of a Runnable. In these situations, you must catch InterruptedException and restore the interrupted status by calling interrupt on the current thread

The provided backoff policies (e.g. FixedBackOffPolicy, ExponentialBackOffPolicy) throw a BackOffInterruptedException without restoring the flag.

Do you think it is possible to restore the flag before throwing the runtime exception?
I can open a PR.

Thank you!

Footnotes

  1. Google Books

@garyrussell
Copy link
Contributor

Good catch, yes, this is a bug. A PR would be welcome.

@mlichtblau
Copy link
Contributor Author

Thanks, I opened #387

artembilan pushed a commit that referenced this issue Oct 19, 2023
Fixes #386

* Update author and copyright

**Cherry-pick to `1.3.x`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants