0
我想用Ruby和ActiveRecord使用多線程。Activerecord使用模塊檢查ID
程序應該是在同一時間通過多個線程訪問同一個數據庫,所以我的想法是檢查id
,像:id % threadnumber = 0
。 但我無法得到這個工作。
我想用這樣的:
Url.where(:id % threadnumber = 0).first
,我認爲超載%
的,但後來我不得不做出一個功能:id
。
這可能嗎?如果不是,我該如何使用模運算符?
這是一個例子:
id => thread number
1 => 1
2 => 2
3 => 3
4 => 2
5 => 1
6 => 3
7 => 1
8 => 2
9 => 3
好感謝!我試過這個,但是:id並沒有工作。現在呢! – Michael