I would like to serialize some objects in console application just before program terminates itself(without adding this code simply in the end of main method)?
Is that possible to solve out?
I would like to serialize some objects in console application just before program terminates itself(without adding this code simply in the end of main method)?
Is that possible to solve out?
You can register a shutDownHook as below:
public class Task implements Runnable {
public void run() {
yourWork();
}
}
public class App{
static {
Runtime.getRuntime().addShutDownHook(new Thread(new Task()));
}
public static void main(String[] args){
.
.
.
}
}