I want to use multithreading with Ruby and ActiveRecord.
The program is supposed to access the same database through multiple threads at the same time, so my idea was to check on id, something like :id % threadnumber = 0.
but I can’t get this to work.
I want to use this:
Url.where(:id % threadnumber = 0).first
and I thought of overloading the %, but then I have to make a function for :id.
Is this possible? If not, how can I use the modulo operator?
This is an example:
id => thread number
1 => 1
2 => 2
3 => 3
4 => 2
5 => 1
6 => 3
7 => 1
8 => 2
9 => 3
1 Answer