我有一个方法 doJob()
每 10 秒运行一次,如下所示。
我想在运行时自定义运行周期。我的意思是,在下午 2 点到 3 点之间,doJob()
每 5 秒运行一次。下午 3 点至 4 点之间 doJob()
每 50 秒运行一次。
是否可以在运行时自定义运行周期?
@Scheduled(cron = "0/10 * * * * ?")
public void doJob() {
}
在本文中http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06
Note that some scheduling requirements are too complicated to express with a single trigger - such as "every 5 minutes between 9:00 am and 10:00 am, and every 20 minutes between 1:00 pm and 10:00 pm". The solution in this scenario is to simply create two triggers, and register both of them to run the same job.
最佳答案
您将无法使用相同的作业,但肯定无法使用两个不同的作业
作业 1(下午 2 点至 3 点之间每 5 秒运行一次)
0/5 * 2-3 * * ?
作业 2(下午 3 点至 4 点之间每 50 秒运行一次)
0/50 * 3-4 * * ?
关于java - 定制@Scheduled Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33625349/