0
我使用線程經常和我不知道這是一個很好的做法:Rails 3.2.8 - 當我將多個數據保存到數據庫時,我應該使用Thread嗎?
def self.create_all_posts
threads = []
self.fetch_all_posts.each do |e|
if e.present?
threads << Thread.new {
self.create(title: e[:title], url: e[:url])
}
end
end
main = Thread.main # The main thread
current = Thread.current # The current thread
all = Thread.list # All threads still running
all.each { |t| t.join }
end