如何暂停石英调度程序中的作业?

发布于 2024-12-09 08:50:43 字数 237 浏览 4 评论 0原文

您好,我正在创建一个应用程序,该应用程序基于 cron 表达式执行类的方法。为此,我正在使用 springquartz,其中我必须在 spring 文件中配置所有这些内容,它工作正常并且作业基于 cron 表达式执行,但现在我想暂停基于 java 类的特定作业的下一次执行关于用户从 UI 中的选择。那么有什么办法可以做到这一点吗?

我可以获得上下文中所有正在运行的作业的详细信息吗?如果是这样,那么我可以过滤作业并尝试暂停该作业以供下次执行。

Hi i am creating an application that executes the method of a class based on a cron expression. 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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青衫负雪 2024-12-16 08:50:43

注入您的 SchedulerFactoryBean。使用它的 getScheduler 方法来获取quartz 调度程序并使用rescheduleJob 或来自quartz API 的其他方法来执行您的任务。

Inject your SchedulerFactoryBean. Use it's getScheduler method to obtain a quartz Scheduler and use rescheduleJob or other methods from quartz API to perform your task.

不及他 2024-12-16 08:50:43

我通过使用以下代码

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);
            }
     }
 }          

I got it work by use of following code

stdScheduler is a 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);
            }
     }
 }          
小清晰的声音 2024-12-16 08:50:43

我们可以使用 stdScheduler.pauseJob(JobKey jobKey) 方法来减少上面代码中提到的循环次数

We can use the stdScheduler.pauseJob(JobKey jobKey) method to reduce the number of loops mentioned in the code above

戈亓 2024-12-16 08:50:43

如果您通过注入或其他方式获得 SchedulerFactoryBean,则有一些方便的方法:

schedulerFactoryBean.getScheduler().standby();
schedulerFactoryBean.getScheduler().start();

直接使用 Quartz 时,这也有效:

@Autowired
private Scheduler scheduler;

...
scheduler.standby();
...
scheduler.start();

If you got hold of the SchedulerFactoryBean by injection or somehow else there are the convenience methods:

schedulerFactoryBean.getScheduler().standby();
schedulerFactoryBean.getScheduler().start();

When using Quartz directly also this works:

@Autowired
private Scheduler scheduler;

...
scheduler.standby();
...
scheduler.start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文