You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Task counts can miss a just-posted task on JRuby #1121
On JRuby, a task that was just posted can be missing from both scheduled_task_count and completed_task_count. For a short time the two counts are equal even though the task hasn't run yet. On CRuby the counts are exact.
JavaThreadPoolExecutor returns Java's getTaskCount and getCompletedTaskCount, which Java documents as approximate. A task handed to an idle worker that hasn't started it yet isn't in the queue and isn't counted as running, so neither count includes it. RubyThreadPoolExecutor counts a task when it is posted, so it doesn't have this gap. The docs here don't mention the difference.
Reproduction
require"concurrent"pool=Concurrent::CachedThreadPool.newpool.post{}# start a worker, so the next task goes to an idle threadsleep0.1missing=01000.timesdodone=Concurrent::Event.newpool.post{done.set}scheduled=pool.scheduled_task_countcompleted=pool.completed_task_countmissing += 1ifscheduled == completed && !done.set?done.waitsleep0.001untilpool.completed_task_count == pool.scheduled_task_countendputs"posted task missing from both counts: #{missing}/1000"
JRuby 10.1.2.0, concurrent-ruby 1.3.8: 952/1000
CRuby 4.0.7, concurrent-ruby 1.3.8: 0/1000
Why it matters
Code that waits for a pool to finish by comparing the two counts can stop waiting too early on JRuby. Rails' Action Cable tests do this, and one of them fails now and then on JRuby because of it.
JavaThreadPoolExecutor could count posted and finished tasks itself, as RubyThreadPoolExecutor does. Or the docs could say the counts are approximate on JRuby.
changed the title [-]scheduled_task_count and completed_task_count miss a just-posted task on JRuby[/-][+]Task counts can miss a just-posted task on JRuby[/+]on Nov 11, 2026
Activity
[-]scheduled_task_count and completed_task_count miss a just-posted task on JRuby[/-][+]Task counts can miss a just-posted task on JRuby[/+]