Active Record 連線池佇列
執行緒安全、公平、LIFO 佇列。供 ConnectionPool
使用,並與其共用監視器。
- A
- C
- D
- N
- P
類別公開方法
new(lock = Monitor.new) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 14 def initialize(lock = Monitor.new) @lock = lock @cond = @lock.new_cond @num_waiting = 0 @queue = [] end
執行個體公開方法
add(element) 連結
將 element
加入佇列。絕不封鎖。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 37 def add(element) synchronize do @queue.push element @cond.signal end end
any_waiting?() 連結
測試是否有任何執行緒目前正在佇列上等待。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 22 def any_waiting? synchronize do @num_waiting > 0 end end
clear() 連結
移除佇列中的所有元素。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 52 def clear synchronize do @queue.clear end end
delete(element) 連結
如果佇列中有 element
,移除並回傳它,否則回傳 nil
。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 45 def delete(element) synchronize do @queue.delete(element) end end
num_waiting() 連結
傳回目前正在這個佇列中等待的執行緒數量。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 30 def num_waiting synchronize do @num_waiting end end
poll(timeout = nil) 連結
移除佇列的開頭。
如果未提供 timeout
,則在可用元素數量嚴格大於目前正在等待的執行緒數量時(也就是說,不要跳過佇列),移除並回傳佇列的開頭。否則,回傳 nil
。
如果提供了 timeout
,則在沒有可用元素時封鎖,等待最多 timeout
秒,直到有元素可用。
引發
-
ActiveRecord::ConnectionTimeoutError
如果提供了timeout
且沒有元素
在 timeout
秒內可用,
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb, line 72 def poll(timeout = nil) synchronize { internal_poll(timeout) } end