public class Test {
public static void main(String[] args)
{
while(true) {
System.out.println("1 ");
}
}
}
What this code does is run for infinite till the program is terminated manually for example give the picture below.
What my requirement is when I manually terminate the execution my output should be like below
1 1 1 Program terminated manually thank you
The above 2 lines of output after I manually terminate the program. Why I need this is I am storing the serializable objects in the file. My code flow is when I working on the program there will be a lot of modifications in the object at end of execution I serialize the updated object into the file. So when I terminate the program manually serialization of the updated object is not done. So I need Serialization should be done even at manual termination.