From 264d30a7bc5ec757ccc1cec92419850c456f850b Mon Sep 17 00:00:00 2001 From: 0z5a Date: Thu, 19 Nov 2026 22:01:00 +0100 Subject: [PATCH] Document that JRuby task counts are approximate On JRuby, scheduled_task_count and completed_task_count come from Java's ThreadPoolExecutor#getTaskCount and #getCompletedTaskCount, which Java documents as approximate. A task handed to an idle worker that has not started it yet is in neither count, so the two can be equal while that task is still pending. RubyThreadPoolExecutor counts a task when it is posted, so the counts are exact there. Say this in the shared macros, which are used for ThreadPoolExecutor and the pools built on it. Fixes #1121 --- lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb b/lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb index b73cff877..bf6005793 100644 --- a/lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb +++ b/lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb @@ -33,10 +33,15 @@ module Concurrent # @!macro thread_pool_executor_attr_reader_scheduled_task_count # The number of tasks that have been scheduled for execution on the pool since construction. + # On JRuby this is Java's `ThreadPoolExecutor#getTaskCount`, which is only approximate: + # a task that was just posted to an idle thread may not be counted until it starts. # @return [Integer] The number of tasks that have been scheduled for execution on the pool since construction. # @!macro thread_pool_executor_attr_reader_completed_task_count # The number of tasks that have been completed by the pool since construction. + # On JRuby this is Java's `ThreadPoolExecutor#getCompletedTaskCount`, which is only approximate. + # A task that was just posted can be missing from both this count and `scheduled_task_count`, + # so the two can be equal while that task has not run yet. # @return [Integer] The number of tasks that have been completed by the pool since construction. # @!macro thread_pool_executor_method_active_count