Shutdown hook for Rails
问题 I'd like to have some cleanup code run when Rails is shutting down - is that possible? My situation is that I have a few threads in the background (I'm using jruby and calling into java) that live for the life of the process and I need to let them know to shut themselves down Thanks! 回答1: Probably should just use the Ruby exit handler, which is a Kernel method: $ irb >> at_exit do ?> puts 'bye...' >> end => #<Proc:0xb79a87e4@(irb):1> >> exit bye... $ 回答2: Within the context of a Rails