I'm writing Java application and I want it can be shut down from the outside (I mean by bash script, or python, or something else).
But simply killing the application is not quite appropriate. This is because I have many running thread some of them are performing I/O
and killing may lead written data to be in inconsistent state. So I want some sort of graceful shutdown. What I found is this:
import sun.misc.Signal;
import sun.misc.SignalHandler;
Signal.handle(new Signal("KILL"), new SignalHandler() {
public void handle(Signal sig) {
//Interrupt all threads and shutdown all services gracefully
}
});
But this is from sun.misc
package and is not a public API. Is there a more appropriate way to gracefully shutdown Java application?