Module: Hsdq::Threadpool
- Included in:
- Hsdq
- Defined in:
- lib/hsdq/threadpool.rb
Overview
This module is used to manage the threads
Instance Method Summary collapse
-
#allow_new_threads? ⇒ Boolean
True if below the max number of allowed thread.
-
#hsdq_start_thread(ignition) ⇒ TheadGroup
Start a new thread and add it to the thread group.
-
#hsdq_threads ⇒ ThreadGroup
Cached ThreadGroup instance holding the threads for a given hsdq class.
-
#hsdq_threads_add(thread) ⇒ Threadgroup
Add a thread to the thread group.
-
#hsdq_threads_count ⇒ Object
The number of thread in the thread group.
-
#max_thread_count(max_count = nil) ⇒ Integer
The maximum number of threads allowed to run at the same time.
-
#paused(paused) ⇒ Object
Set paused flag.
-
#paused? ⇒ Boolean
True is paused.
Instance Method Details
#allow_new_threads? ⇒ Boolean
Returns true if below the max number of allowed thread.
26 27 28 |
# File 'lib/hsdq/threadpool.rb', line 26 def allow_new_threads? hsdq_threads_count < max_thread_count && !paused? end |
#hsdq_start_thread(ignition) ⇒ TheadGroup
Start a new thread and add it to the thread group
51 52 53 54 55 |
# File 'lib/hsdq/threadpool.rb', line 51 def hsdq_start_thread(ignition) t = Thread.new(&ignition) p "New thread: #{t}" hsdq_threads_add t end |
#hsdq_threads ⇒ ThreadGroup
Cached ThreadGroup instance holding the threads for a given hsdq class
32 33 34 |
# File 'lib/hsdq/threadpool.rb', line 32 def hsdq_threads @hsdq_threads ||= ThreadGroup.new end |
#hsdq_threads_add(thread) ⇒ Threadgroup
Add a thread to the thread group
39 40 41 |
# File 'lib/hsdq/threadpool.rb', line 39 def hsdq_threads_add(thread) hsdq_threads.add thread end |
#hsdq_threads_count ⇒ Object
Returns the number of thread in the thread group.
44 45 46 |
# File 'lib/hsdq/threadpool.rb', line 44 def hsdq_threads_count hsdq_threads.list.size end |
#max_thread_count(max_count = nil) ⇒ Integer
The maximum number of threads allowed to run at the same time. This is setter and a cached getter.
8 9 10 11 |
# File 'lib/hsdq/threadpool.rb', line 8 def max_thread_count(max_count=nil) @max_thread_count = max_count if max_count @max_thread_count ||= hsdq_opts[:max_thread_count] || 10 end |
#paused(paused) ⇒ Object
Set paused flag
15 16 17 |
# File 'lib/hsdq/threadpool.rb', line 15 def paused(paused) @paused = paused end |
#paused? ⇒ Boolean
Returns true is paused.
20 21 22 23 |
# File 'lib/hsdq/threadpool.rb', line 20 def paused? @paused = false if @paused.nil? @paused end |