I’ve been working on getting our Rails 2.3.8 app running correctly under JRuby. Everything works great until I enable config.threadsafe! in order to achieve the concurrency that JRuby offers. This caused modules and classes in lib/ to no longer autoload.
with config.threadsafe! enabled:
$ ruby script/runner -e production 'p Sim::Sim200Provisioner'
/Users/amchale/.rvm/gems/jruby-1.5.1@web-services/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant Sim::Sim200Provisioner (NameError)
from (eval):1
with config.threadsafe! disabled:
$ ruby script/runner -e production 'p Sim::Sim200Provisioner'
Sim::Sim200Provisioner
The file in question is lib/sim/sim200_provisioner.rb where Sim is app/models/sim.rb. Rails normally has no trouble finding and loading the file.
Do I need to manually require all of our libs, or is there a more Rails-like way to handle it that I’m missing?
The documentation of
threadsafe!mentions that it disables automatic dependency loading. The reason is that there might be race conditions during the loading of files if two or more threads both decide they are still missing a certain class.Instead, you should manually
requireall files you need in aninitializer.