Currently I have a large JRuby application running on Tomcat. I have
generic scripts for managing my tomcat applications. However, my JRuby
app shuts down before all the currently running requests are done. So
I’m trying to get my app to wait them to finish before terminating.
My thoughts so far:
- Trap the “TERM” signal with “Signal.trap”
- Respond to load balancer to give the server no more traffic
- ??? Wait for remaining request threads to finish responding
- Normal cleanup in “at_exit”
The problem I have is with #3. I’m having difficulty trying to figure
out if there are any web requests still processing. I can see here
(http://wiki.apache.org/tomcat/FAQ/Monitoring) that there are some
useful JMX beans I could use but I don’t know how to import the classes
(How does “Catalina: type=ThreadPool,name=”[depends]"" translate to a
java_import?). Hell, even after figuring out how to get in the bean I’m
going to have to play around to see if I can get the information I need
(Get the active thread count, but does it include everything not just
request threads? Am I going to have to iterate and check the information
for each thread? etc.).
Any suggestions? Perhaps I’m going about this the completely wrong way.
Version info: Java 6; JRuby 1.67; Ruby 1.8.7