Reputation: 27270
Is there any way to get notified of JVM shutting down or System.exit call before the actual shutdown? I want this, so my application will be able to make a clean exit. I realize that such thing is unlikely to exist, but still, maybe there is something like this?
Upvotes: 8
Views: 2437
Reputation: 62623
There's Runtime.getRuntime().addShutdownHook()
method that you might want to explore.
Upvotes: 3
Reputation: 4017
Have a look at Runtime.addShutdownHook
From the API docs:
The Java virtual machine shuts down in response to two kinds of events:
Using Runtime.addShutdownHook
you can run code in those cases.
Upvotes: 14