I have a simple Java class that runs in a look, doing something.
public class SomeClass{
public int counter = 0;
public void doSomehing(){
while(true){
doSomethingElse();
counter++;
}
}
I would like to execute some code only when the Java program is forced to stop (e.g. by hitting a terminate button in the IDE or when stopping the program with the operating system (e.g. writing the counter to a file). Is this possible? Or is the very nature of overwriting Java with a forced exit not allowing for such a exit behavior?