I am trying to add a shutdown hook via Runtime.getRuntime().addShutdownHook()
in a Spring Gradle application.
I tried adding an anonymous thread subclass to the Application.java class from this exact tutorial So that it looks like this:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
Thread thread = new Thread() {
public void run() {
System.out.println("Shutdown Thread!");
}
};
Runtime.getRuntime().addShutdownHook(thread);
SpringApplication.run(Application.class, args);
}
}
However, I am not seeing the desired behavior: printing "Shutdown Thread!" on exiting the application. What is going wrong here?
edit: I have been shutting it down using control + c
on the terminal where it is running. I am running it on the OSX terminal