I have a cleanup method on my Java project. I would like to have my cleanup method triggered once I push the "Stop Debugging" while debugging my Java code on IntelliJ. Is it possible? I would settle even with some writings to log.
JVM shutdown hook will help:
Thread printingHook = new Thread(() -> System.out.println("In the middle of a shutdown"));
Runtime.getRuntime().addShutdownHook(printingHook);
See this document for more details.