Skip to content

feat: use only one, configurable ExecutorService #546

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

Merged
merged 8 commits into from
Sep 21, 2021
Merged

feat: use only one, configurable ExecutorService #546

merged 8 commits into from
Sep 21, 2021

Conversation

metacosm
Copy link
Collaborator

@metacosm metacosm commented Sep 17, 2021

Fixes #540
cc @lburgazzoli

@metacosm metacosm requested a review from csviri September 17, 2021 17:02
@@ -146,7 +124,13 @@ private void executeBufferedEvents(String customResourceUid) {
latestCustomResource.get(),
retryInfo(customResourceUid));
log.debug("Executing events for custom resource. Scope: {}", executionScope);
executor.execute(new ExecutionConsumer(executionScope, eventDispatcher, this));
executor.execute(() -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm probably going to revert that change so that we can override toString to get more precise debugging information on the Runnable… 🥲

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant eliminating the ExecutionConsumer is elegant here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understood that but like I said, I actually need to re-introduce some equivalent form of it :)

executor.execute(new ExecutionConsumer(executionScope, eventDispatcher, this));
executor.execute(() -> {
// change thread name for easier debugging
Thread.currentThread().setName("EventHandler-" + controllerName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? It looks a bit strange that we change the thread name on every execution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that was previously done when initializing the thread pool by specifying the thread factory. We can't do that anymore so the only alternative I could think of at that point was to rename the thread when it executes.

@lburgazzoli
Copy link
Collaborator

LGTM

@metacosm metacosm force-pushed the fix-540 branch 2 times, most recently from 97772a4 to ef27cba Compare September 21, 2021 16:21
The goal is to make sure the thread pool is properly started and shut
down at appropriate time, while getting it ready for instrumentation.
This should also address the tests issue where the executor was shut
down at the end of one test and never re-started at the beginning of the
next one thus leading to tasks being rejected.
This is done by moving the close method to static and nulling the
singleton so that it can be re-created on next Operator start if needed.
This is needed for proper testing support.
@metacosm metacosm merged commit 63c1a8d into master Sep 21, 2021
@metacosm metacosm deleted the fix-540 branch September 21, 2021 21:35
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

Successfully merging this pull request may close these issues.

Using only one instance of ScheduledExecutorService
3 participants