Search code examples
intellij-idea

Intellij: Can I define a post "Stop Debugging" action (method call, log line, etc.)?


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.


Solution

  • 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.