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

Termination condition #2

Open
pditommaso opened this issue Jun 5, 2024 · 2 comments
Open

Termination condition #2

pditommaso opened this issue Jun 5, 2024 · 2 comments

Comments

@pditommaso
Copy link

Can you elaborate about the need for a while loop in the awaitTermination method?

while (!executorService.isTerminated()){
executorService.awaitTermination(TIMEOUT, TimeUnit.SECONDS);
}

@jorgee
Copy link
Owner

jorgee commented Jun 7, 2024

The executor shutdown schedules the shutdown after all tasks have been finished. This call is non blocking so we need to do awaitTermination. This call require a timeout. The wait is to ensure processing takes more than the timeout

@pditommaso
Copy link
Author

I see, but the timeout is expected to be provided as a protection to prevent a program from hanging forever if, for some reason, the termination condition cannot be reached.

I'd argue it could be better to avoid the use of the while (!executorService.isTerminated()) loop and eventually use a long timeout interval.

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

No branches or pull requests

2 participants