Dynamic Job Scheduling with Quartz or any other java api

荒凉一梦 提交于 2019-12-25 02:18:42

问题


I have an UI Interface where user can define Job name, interval, active/Inactive etc.

How we can achieve this with Quartz Scheduler or any java/Spring api ?

Ex. Suppose any Quartz job is started and interval is set as 10 min, So in ideal case job will run in next 10 min interval. But every time job runs we want to fetch the latest interval from database and schedule it.

10:00 Job runs and in the database interval is set to 10 min 10:10 Job runs and in the database interval is set to 20 min

So next time job should run at 10:30


回答1:


If you use Quartz, you can implement a custom Trigger. Your implementation would lookup the value in the database and return when the next time the run should happen in the getFireTimeAfter.

Another option is to use Spring Scheduling APIs and implement the Trigger interface. Same here, the nextExecutionTime method would decide when the next run should happen.

The advantage of using a custom implementation is that you have full control over the triggering logic (like in your case, do a lookup in the database and dynamically set the next run time).



来源:https://stackoverflow.com/questions/52099431/dynamic-job-scheduling-with-quartz-or-any-other-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!