Skip to content

Fix doShutdown() task counting - #73

Merged
dwalluck merged 3 commits into
Commonjava:masterfrom
dwalluck:fix-shutdown-drain
Aug 26, 2026
Merged

Fix doShutdown() task counting#73
dwalluck merged 3 commits into
Commonjava:masterfrom
dwalluck:fix-shutdown-drain

Conversation

@dwalluck

Copy link
Copy Markdown
Contributor

The doShutdown() method counted the number of threads created rather than the number of tasks submitted. It was also off by one when draining.

@dwalluck
dwalluck force-pushed the fix-shutdown-drain branch from af409a1 to 2cdaa55 Compare August 24, 2026 19:33
@dwalluck
dwalluck requested a review from rnc August 25, 2026 12:26
}
}

exec.shutdown();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While unlikely what happens if svc.take throws InterruptedException ? Should exec.shutdown/time.cancel be in a finally block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! In fact, we should put it all in a try and move that to finally. Also I noticed a catch ( InterruptedException e ) without Thread.currentThread().interrupt(); looking now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changes made in 8475807, but I'll need to rebase. Code is the same just moved to try/finally.

{
svc.submit( () -> shutdownAction.apply( tracker ) );
submitted++;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While both work, was there a reason to use the for loop instead of streams? i.e. instead of

int submitted = cache.size();
cache.values().forEach( tracker -> svc.submit( () -> shutdownAction.apply( tracker ) ) );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair. It should be the same. The only reason I changed it was to count submitted, which should be equal to the cache.size().

@dwalluck dwalluck Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in adee2f4. Need to rebase, though.

The `doShutdown()` method counted the number of threads created rather
than the number of tasks submitted. It was also off by one when draining.
@dwalluck
dwalluck force-pushed the fix-shutdown-drain branch from adee2f4 to c179c85 Compare August 26, 2026 13:32
@dwalluck
dwalluck merged commit c4530e9 into Commonjava:master Aug 26, 2026
1 check passed
@dwalluck
dwalluck deleted the fix-shutdown-drain branch August 26, 2026 16:34
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.

2 participants