Skip to content

Commit 4f8594e

Browse files
committed
Merge pull request #47 from jdantonio/gh-33
Gh 33 - Adding method #status to FixedThreadPool
2 parents 88d5120 + 665a65d commit 4f8594e

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-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

spec/concurrent/cached_thread_pool_shared.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@
100100
end
101101
end
102102

103+
context '#status' do
104+
105+
it 'returns an array' do
106+
subject.stub(:warn)
107+
subject.status.should be_kind_of(Array)
108+
end
109+
end
110+
103111
context '#idletime' do
104112

105113
subject{ described_class.new(idletime: 42) }

spec/concurrent/fixed_thread_pool_shared.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@
9494
end
9595
end
9696

97+
context '#status' do
98+
99+
it 'returns an array' do
100+
subject.stub(:warn)
101+
subject.status.should be_kind_of(Array)
102+
end
103+
end
104+
97105
context '#idletime' do
98106

99107
it 'returns zero' do

0 commit comments

Comments
 (0)