Skip to content

Instantly share code, notes, and snippets.

@reidmorrison
Created August 14, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidmorrison/5e932a84d04f214ac5a2 to your computer and use it in GitHub Desktop.
Save reidmorrison/5e932a84d04f214ac5a2 to your computer and use it in GitHub Desktop.
JRuby startup under load causes invalid LoadError - no such file to load
# Fixes "LoadError" "no such file to load" on JRuby 1.7
# Place at the top of application.rb
# Override Kernel#autoload and Module#autoload to #require when Web Server or Worker
# so that classes are all loaded in highly concurrent environments
# Also forces the code to be loaded up front instead of on demand in production
begin
# Since Rails has not yet been loaded we have to use the env vars
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
if (['production', 'release', 'hotfix'].include?(rails_env))
def Kernel
def autoload(module_, filename)
require filename
end
end
def Module
def autoload(module_, filename)
require filename
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment