Announcement Announcement Module
No announcement yet.
Reschedule a Quartz task from a quartz task Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reschedule a Quartz task from a quartz task

    We're writing our first quartz jobs in spring. We want to be able to reschedule at runtime, mostly to turn on or off, and change timing. We have our cronExpressions in a property file and when that property file is refreshed we want to pick up the changes and apply them. This seems like a natural thing to want, and just as naturally to write the watch thread for the property file change in quartz itself.

    But I am having problems. Everything I've tried has failed for one reason or another. I tried handing the triggers to the watch job via spring, even making them singletons but quartz does not change. I tried getting the spring context so I could get the schedule factory as I saw on several help pages, but inside a quartz task AppContextAware and @Autowired don't work.

    I tried several other derivations of the above plans, and they failed as well. How can I reschedule a quartzjobbean from another quartzjobbean. Or is there an easier/better method?

  • #2
    I have a setup that looks like this right now:

    protected void executeInternal(JobExecutionContext jobCtx) throws JobExecutionException {
    Scheduler scheduler = jobCtx.getScheduler();
    CronTriggerBean trigger = (CronTriggerBean) scheduler.getTrigger(beanName, Scheduler.DEFAULT_GROUP);
    But I can watch this in debug and the running threads never reschedule.


    • #3
      Aha, what was missing was:

      scheduler.rescheduleJob(beanName, Scheduler.DEFAULT_GROUP, trigger);