new(spec)
public
Creates a new
ConnectionPool object. spec is a ConnectionSpecification object
which describes database connection
information (e.g. adapter, host name, username, password, etc), as well as
the maximum size for this ConnectionPool.
The default ConnectionPool maximum size is 5.
Show source
def initialize(spec)
super()
@spec = spec
@checkout_timeout = (spec.config[:checkout_timeout] && spec.config[:checkout_timeout].to_f) || 5
if @idle_timeout = spec.config.fetch(:idle_timeout, 300)
@idle_timeout = @idle_timeout.to_f
@idle_timeout = nil if @idle_timeout <= 0
end
@size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
@thread_cached_conns = Concurrent::Map.new(initial_capacity: @size)
@connections = []
@automatic_reconnect = true
@now_connecting = 0
@threads_blocking_new_connections = 0
@available = ConnectionLeasingQueue.new self
@lock_thread = false
reaping_frequency = spec.config.fetch(:reaping_frequency, 60)
@reaper = Reaper.new(self, reaping_frequency && reaping_frequency.to_f)
@reaper.run
end