java定时器偶尔重复推送_在Java中创建重复的定时器提醒
使用timer.scheduleAtFixedRate()來安排它每兩秒重復一次:
Schedules the specified task for repeated fixed-rate execution, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.
從用于Timer.cancel()的javadoc:
Terminates this timer, discarding any currently scheduled tasks. Does not interfere with a currently executing task (if it exists). Once a timer has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.
編輯:
關于執行一個任務一次的Timer的內部執行線程:
After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer’s task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur. By default, the task execution thread does not run as a daemon thread, so it is capable of keeping an application from terminating. If a caller wants to terminate a timer’s task execution thread rapidly, the caller should invoke the timer’s cancel method.
總結
以上是生活随笔為你收集整理的java定时器偶尔重复推送_在Java中创建重复的定时器提醒的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java搭建maven项目_Eclips
- 下一篇: mysql 5.5 barracuda_