Is there is an oposite tool to static initializer in Java

Static blocks are executed when class is loading even before the public static void main starts. Is there any possibility to run a certain code just before the program close?

Jon Skeet
people
quotationmark

I think you're looking for Runtime.addShutdownHook. It's not a language level construct in the way that static initializer blocks are, but I think it'll do what you want.

You should be careful with shutdown hooks though - see the documentation for various warnings around them.

people

See more on this question at Stackoverflow