class Mqjob::ThreadPool

Public Class Methods

new(num_threads, opts = {}) click to toggle source
Calls superclass method
# File lib/mqjob/thread_pool.rb, line 5
def initialize(num_threads, opts = {})
  super
  @job_finish = ConditionVariable.new
  @job_mutex = Mutex.new
end

Public Instance Methods

kill() click to toggle source
Calls superclass method
# File lib/mqjob/thread_pool.rb, line 30
def kill
  super

  @job_finish.broadcast
end
ns_execute() click to toggle source
Calls superclass method
# File lib/mqjob/thread_pool.rb, line 18
def ns_execute
  super

  @job_finish.signal
end
post(*args, &task) click to toggle source

NOTE 使用非缓冲线程池,防止消息丢失

Calls superclass method
# File lib/mqjob/thread_pool.rb, line 12
def post(*args, &task)
  wait

  super
end
shutdown() click to toggle source
Calls superclass method
# File lib/mqjob/thread_pool.rb, line 24
def shutdown
  super

  @job_finish.broadcast
end
wait() click to toggle source
# File lib/mqjob/thread_pool.rb, line 36
def wait
  @job_mutex.synchronize do
    while running? && (scheduled_task_count - completed_task_count >= max_length)
      @job_finish.wait(@job_mutex, 0.05)
    end
  end
end