Closed
Description
In the scenario in which a ThreadPoolExecutor has received #shutdown
and there are active threads/tasks, there is an inconsistency between what JRuby and C Ruby return for #shutdown?
:
- JRuby will return
#shutdown? => true
while there are still active threads/tasks, at the same time as#shuttingdown? => true
. Java's executor service narrowly defines#isShutdown
as "no new tasks will be accepted" which is distinct from#isTerminated
which is "all tasks have completed following shut down". - The Ruby implementation does more of what my expectations are:
#shutdown? => false
while there are still active threads/tasks, at the same time as#shuttingdown? => true
.
It's fairly easy to work around this inconsistency using executor.shutdown? && !executor.shuttingdown?
to achieve the same result in both rubies for determining when there are no more threads/tasks on a shutdown executor. It would be nice if the behavior was aligned.
Metadata
Metadata
Assignees
Labels
No labels
Activity
bensheldon commentedon Feb 29, 2024
Another discovery here is that in J Ruby, once
ThreadPoolExecutor#kill
is called, it's necessary to do await_for_termination
to achieve a fully shutdown and terminated executor.This is now the shutdown wrapper I'm using:
This is similar to the usage example given in Java:
eregon commentedon Feb 29, 2024
That seems worth fixing in https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb
bensheldon commentedon Feb 29, 2024
Thanks! This line does look like the culprit:
concurrent-ruby/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb
Lines 67 to 69 in eae2851
I missed that last night because I got distracted trying to discover the need for the feature-check in
#shuttingdown?
:concurrent-ruby/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb
Lines 59 to 64 in eae2851
That was introduced 9+ years ago (I couldn't find the exact place), but I'm not sure if
isTerminating
/isTerminated
only exist for certain implementations or versions of Java. Any idea how to check that?bensheldon commentedon Feb 29, 2024
Aha, it looks like just
isTerminating
maybe didn't exist in Java 6, butisTerminated
did. ok, I think I have enough for a PR 👍shuttingdown?
,shutdown?
#1042kill
willwait_for_termination
in JRuby #1044