Skip to content

Commit c9b6d8a

Browse files
committed
GH-33 - Adding method status to FixedThreadPool.
The method `status` was accidentally removed a few months ago, this is a deprecated method and we gonna have to remove it soon, but for now we're adding the method back with a warn message saying that this is a deprecated method.
1 parent 8b6bc97 commit c9b6d8a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/concurrent/java_thread_pool_executor.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ def remaining_capacity
102102
@max_queue == 0 ? -1 : @executor.getQueue.remainingCapacity
103103
end
104104

105+
# This method is deprecated and will be removed soon.
106+
# This method is supost to return the threads status, but Java API doesn't
107+
# provide a way to get the thread status. So we return an empty Array instead.
108+
def status
109+
warn '[DEPRECATED] `status` is deprecated and will be removed soon.'
110+
warn "Calls to `status` return an empty Array. Java ThreadPoolExecutor does not provide thread's status."
111+
[]
112+
end
113+
105114
# Is the thread pool running?
106115
#
107116
# @return [Boolean] +true+ when running, +false+ when shutting down or shutdown

lib/concurrent/ruby_thread_pool_executor.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def running?
9090
@mutex.synchronize { @state == :running }
9191
end
9292

93+
# Returns an array with the status of each thread in the pool
94+
#
95+
# This method is deprecated and will be removed soon.
96+
def status
97+
warn '[DEPRECATED] `status` is deprecated and will be removed soon.'
98+
@mutex.synchronize { @pool.collect { |worker| worker.status } }
99+
end
100+
93101
# Is the thread pool shutdown?
94102
#
95103
# @return [Boolean] +true+ when shutdown, +false+ when shutting down or running

lib/concurrent/ruby_thread_pool_worker.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ def last_activity # :nodoc:
2525
@mutex.synchronize { @last_activity }
2626
end
2727

28+
def status
29+
@mutex.synchronize do
30+
return 'not running' if @thread.nil?
31+
@thread.status
32+
end
33+
end
34+
2835
# @!visibility private
2936
def kill # :nodoc:
3037
@mutex.synchronize do

0 commit comments

Comments
 (0)