Ruby Multi Threading With Pool Size

+6598765432|Person1
.
.
.
.
.
+6587654321|Person100000
POOL_SIZE = 10

def send(strPhoneNumber, strMessage)
`./adb shell service call isms 7 i32 0 s16 "null" s16 "#{strPhoneNumber}" s16 "null" s16 "'#{strMessage}'"`
end

def read_name_list
q = Queue.new
rows=(`cat list.txt`).split("\n")
for z in 0..rows.length-1
row=rows[z]
cells=row.split('|')
h=Hash.new
h['number']=cells[0]
h['name']=cells[1]
q.push(h)
end
return q
end

q = read_name_list
workers = (POOL_SIZE).times.map do
Thread.new do
begin
while h = q.pop(true)
message='Hi %s' % h['name']
send(h['number'],message)
end
rescue ThreadError
end
end
end

workers.map(&:join)
def do_some_task(param)
puts param
end

POOL_SIZE = 10

q = Queue.new
101.times{|i| q.push(i)}

workers = (POOL_SIZE).times.map do
Thread.new do
begin
while n = q.pop(true)
do_some_task(n)
end
rescue ThreadError
end
end
end

workers.map(&:join)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.