Search code examples
javaactionlistenerapplication-close

java, Declaring an method which runs before application close


I want to make some actions just before my application close.

I see there are action listeners but i have no frame or similar thing. Just an only java file.

How can I able to set some kind of control?


Solution

  • I want to make some actions just before my application close.
    

    You're probably looking for a shutdown hook:

    Runtime.getRuntime().addShutdownHook(...)
    

    Here's a SO question (and great answers) asking for practical uses of shutdown hooks:

    Useful example of a shutdown hook in Java?