What happens if a TimerTask takes longer to execute than the specified interval?
java, multithreading, timer
Solution
Timer's documentation says the following:
Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.
That is, concurrent `TimerTask` threads will not be running. The tasks will accumulate into a queue. This may or may not be appropriate (more likely, not).
Problem
When using `Timer.schedule(TimerTask task, long delay, long period)` (i.e. with fixed-delay execution), what happens if the specified `TimerTask`'s `run()` method takes longer than `period` to complete? Is it possible that two concurrent `TimerTask` threads will be running because of this? And if so, is there a way to avoid it?