How i can run my TimerTask everyday 2 PM

后端 未结 9 1671
说谎
说谎 2020-12-01 02:48

I want to execute a job everyday 2PM . Which method of java.util.Timer i can use to schedule my job?

After 2Hrs Run it will stop the job and reschedule

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 03:30

    You could use Timer.schedule(TimerTask task, Date firstTime, long period) method, setting firstTime to 2PM today and the setting the period to 24-hours:

    Schedules the specified task for repeated fixed-delay execution, beginning at the specified time. Subsequent executions take place at approximately regular intervals, separated by the specified period.

提交回复
热议问题