Suppose I make a few calls to the following function:
public void StartTimedRuns(){
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask(){
public void run(){
//do something that takes less than a minute
}
}, 0, 60*1000);
}
My understanding is that a bunch of threads will be running simultaneously at this point. That is, each timer instance will be spawning short-lived threads at 1-minute intervals.
Suppose I install a shutdown hook (to run when I press Control-C) per the instructions here:
The shutdown hook will cancel all the timers. (Assume that I store the timers in a class-level collection)
Can I guarantee that all the active threads will run to completion before the VM exits?
Related to this, does the shutdown hook only get called when the threads all exit?