Created
May 6, 2014 02:11
-
-
Save pond/4c2feec7200c557d69fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#$ rails new foo | |
#$ cd foo | |
# <set up config/database.yml to use Postgres with "pool: 1"> | |
# development: | |
# adapter: postgresql | |
# encoding: utf8 | |
# database: foo_development | |
# pool: 1 | |
# <add "gem 'pg'" to Gemfile> | |
#$ bundle install | |
#$ rake db:drop; rake db:create; rake db:migrate | |
#$ rails generate scaffold post title body:text published:boolean | |
#$ rails c | |
# <Do a few Post.create!(title:"hello", body:"world")> | |
# <Then...> | |
finished=[] | |
1.upto(2) do |i| | |
finished[i]="." | |
Thread.new do | |
puts "THREAD START #{i} #{Thread.current.inspect}" | |
1.upto(50) do | |
Post.first.reload | |
Post.last.reload | |
end | |
print "THREAD DONE #{i} #{Thread.current.inspect}: " | |
finished[i]="*" | |
puts finished.join('') | |
# COMMENT THIS OUT and only 1 thread gets to finish. | |
# LEAVE THIS IN and both threads finish. | |
ActiveRecord::Base.connection_pool.disconnect! | |
end | |
sleep(1) | |
puts "COUNT DONE #{i}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment