[英]how to suspend job in quartz scheduler?
Hi i am creating an application that executes the method of a class based on a cron expression. 您好我正在创建一个基于cron表达式执行类方法的应用程序。 For that i am using spring quartz in which i have to configure all these stuffs in my spring-file it works fine and jobs are executing based on the cron expression, But now i want to suspend the next execution of particular job in java class based on the choice of a user from UI.
为此,我使用spring quartz,我必须在我的spring文件中配置所有这些东西,它工作正常,并且作业正在执行基于cron表达式,但现在我想暂停下一个执行基于java类的特定工作从UI中选择用户。 Then is there any way to do this ??
那有什么办法可以做到这一点?
can i get the details of all running job it the context ? 我可以在上下文中获得所有正在运行的工作的详细信息吗? if so then i can filter the jobs and try to suspend that job for next execution.
如果是这样,那么我可以过滤作业并尝试暂停该作业以便下次执行。
Inject your SchedulerFactoryBean . 注入SchedulerFactoryBean 。 Use it's
getScheduler
method to obtain a quartz Scheduler and use rescheduleJob or other methods from quartz API to perform your task. 使用它的
getScheduler
方法获取石英调度程序并使用rescheduleJob或quartz API中的其他方法来执行您的任务。
I got it work by use of following code 我通过使用以下代码使其工作
stdScheduler is a scheduleFactoryBean stdScheduler是scheduleFactoryBean
String groupnames[] = stdScheduler.getJobGroupNames();
for (String groupName : groupnames) {
String[] jobNames = stdScheduler.getJobNames(groupName);
for (String jobName : jobNames) {
if (jobName.equals("jobName")) {
stdScheduler.pauseJob(jobName, groupName);
}
}
}
我们可以使用stdScheduler.pauseJob(JobKey jobKey)方法来减少上面代码中提到的循环数
If you got hold of the SchedulerFactoryBean by injection or somehow else there are the convenience methods: 如果您通过注入或其他方式获得SchedulerFactoryBean,则有方便的方法:
schedulerFactoryBean.getScheduler().standby();
schedulerFactoryBean.getScheduler().start();
When using Quartz directly also this works: 当直接使用Quartz时,这也适用:
@Autowired
private Scheduler scheduler;
...
scheduler.standby();
...
scheduler.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.