The document discusses thread safety in JRuby on Rails applications. It explains that prior to Rails 2.2, each JRuby instance had its own database connection, but newer versions use connection pooling so multiple threads can share database connections through a single JRuby instance. It also covers using ActiveRecord connection pooling and JNDI lookup to configure database connections in a thread-safe way when using JRuby on Rails.
12. Demo Code
10.times do
Thread.new do
ActiveRecord::Base.connection_pool
.with_connection do |c|
ret = c.execute(quot;select connection_id()quot;)
puts quot;Connection ID: %squot; % ret.fetch_row
end
end
end
19. JNDI Look-up
Look-up
Reference
Connection
Client Database
Pool
Data
Source
20. Java EE Application Server
Connection Pooling
Connect or
Check-out Reconnect
ActiveRecord App Server
ActiveRecord Connection Connection
Pool Pool
Connection Connection
Check-in Disconnect
Database