有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为给定时间安排作业

我有一项任务,在规定的时间内每天都要完成

我有一个调度程序来安排那个任务。但是,例如,当我在下午2点启动调度器时,第二天的时间安排为下午2点,如果在下午3点启动,则安排为第二天的下午3点

但我希望在计划开始时,但该任务应该在给定的时间执行。 我只是在用毫秒表示时间

是以毫秒为单位传递时间的任何方法,并且调度程序仅在给定时间执行

如果有人知道,请回复


共 (3) 个答案

  1. # 1 楼答案

    如果您需要一个简单的解决方案或不想使用框架,请查看java.util.Timer#scheduleAtFixedRate(TimerTask task, Date firstTime, long period)

    Fixed-rate execution is appropriate for recurring activities that are sensitive to absolute time, such as ringing a chime every hour on the hour, or running scheduled maintenance every day at a particular time. It is also appropriate for recurring activities where the total time to perform a fixed number of executions is important, such as a countdown timer that ticks once every second for ten seconds. Finally, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain synchronized with respect to one another.

  2. # 2 楼答案

    总是有^{}来做这件事,看看它的^{}here是一个快速的例子