How do I implement graceful termination in Java?
问题 Say for instance I have my application running in a Linux terminal and I press "CTRL+C" on my keyboard to kill the process it will terminate the Java program. Is there any way to catch this "request" in my Java application so I can shut it down gracefully and release all resources/write logs. I have several different threads running if it makes a difference to the response. I know you have have an addShutDownHook, but as written in the Java documentation, it isn't called under certain