I want to execute a task in every hour, but I found the Timer can only set period.
My Requirement is:
- When I start the timer, the task will be executed immediately.
- Run at each hour. If I start the program at 1:20, it will be executed at once. The next time to execute is 2:00. and the next is 3:00, and so on.
- If I start the program at 1:20, and the task does not finsihed at 2:00, The task of 2:00 will be delayed. When the task of 1:20 is finished, the task of 2:00 will be executed at once.
I think the Timer of JDK only provide the period between 2 tasks. If I start the program at 1:20, the second one only can be executed at 2:20, the third one only can be executed at 3:20. So I don't know how to implement a custom timer.