I have two methods. The first one remotely executes an executable and the second one stars talking with an executable. The executable is a web-service. The first step does not return the true (executed through shell) because it starts and waits for the second step. Is there a way to execute the first method and the second method in parallel?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use thread.
t1 = Thread.new do
first_method
end
second_method
t1.join
回答2:
Besides the stock threads support I'd like to mention the great Ruby gem Parallel
It can spawn processes in parallel and utilize multiple CPUs/cores at the same time.
回答3:
you can use ruby's threads to do that. You can check out the links so you can have an ideia of what you can do with threads.
http://www.tutorialspoint.com/ruby/ruby_multithreading.htm
http://ruby-doc.org/core-2.0/Thread.html