So I have a printwriter that will occasionally write to a file ("occasionally" here meaning "periodically after a certain number of specified events").
Now if these events happen to be too few, the log file may end up empty when the application is terminated (Ctrl + C).
I could, of course, flush after every println, but that would defeat the purpose of having a non-auto-flush printwriter (which is the only kind that can be created anyway if I want to pass a File as a constructor argument).
Is there a onApplicationKill-thing in Java I could instrument to flush the writer once when the application is terminated? Or something to detect when the current thread is killed?