I recently applied a Rails application that uses threads and made several discoveries:
-, - (.. ) , . , . , hash/array , , , , , , .
-, ActiveRecord, , . , . , Rails > 2.2, , , . ActiveRecord , , .
, :
mutex = Mutex.new
my_array = []
threads = []
1.upto(10) do |i|
threads << Thread.new {
begin
do_some_stuff
mutex.synchronize {
my_array[i] = some_computed_value
}
ensure
ActiveRecord::Base.connection_pool.release_connection
end
}
}
threads.each {|t| t.join}
, , JRuby. , JRuby - , . , - , .