Announcement Announcement Module
No announcement yet.
Rescheduling Quartz job Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rescheduling Quartz job

    Is it possible to reschedule a quartz job, once it's already been instantiated, registered and triggered?

    I have a 'directory listener' which triggers 5 seconds after my application initialization. It runs only once and it works just fine. Now I need to reschedule it on-demand, e.g. accept an outside call (to some servlet/controller/hessian/whatever) and reschedule that job to be triggered after some delay (e.g. 30 seconds). The client requesting the rescheduling is not interested in the job outcome.

    I couldn't find a way to achieve that ellegantly (read: in a spring way).

    This is part of my app.ctx:
            <!-- runs 5 seconds after app init, e.g. client start -->
            <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
                    <property name="jobDetail">
                            <ref bean="directoryListenerJob"/>
                    <property name="startDelay"><value>5000</value></property>
                    <property name="repeatInterval"><value>1</value></property>
                    <property name="repeatCount"><value>0</value></property>
            <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">^M
                    <property name="triggers">^M
                                    <ref local="cronTrigger"/>^M
                                    <ref local="simpleTrigger"/>^M


  • #2

    Thats exactly i'm looking for at the moment.
    Has anyone find a way to do this?

    My problem is not quite the same as above. But similar..
    This is what I have in my application context:

    <bean id="performanceExtractorService" class="com.bla.advance.performance.webapp.service.impl.PerformanceExtractorServiceImpl" singleton="false">
            <property name="emailService" ref="emailService"/>
        <bean id="performanceExtractorJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="name" value="performanceExtractorJob"/>
            <property name="group" value="performanceExtractorJobGroup"/>
            <property name="targetObject" ref="performanceExtractorService"/>
            <property name="targetMethod" value="gatherAndSendReport"/>
            <property name="concurrent" value="false"/>
      <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean" singleton="true">
            <property name="name" value="performanceExtractorTrigger"/>
            <property name="group" value="performanceExtractorTriggerGroup"/>
            <property name="jobDetail" ref="performanceExtractorJob"/>
            <!-- 10 seconds -->
            <property name="startDelay" value="10000"/>
            <!-- repeat every 5 hours -->
            <property name="repeatInterval" value="18000000"/>
    i.e. the difference is that I invoke on a normal class that does not extend Spring's QuartzJobBean. I wanted to modify the trigger on a class "ConfigurationLoader":

    public class ConfigurationLoader {
      Object simpleTrigger = wac.getBean("simpleTrigger");
  "bean is of type " + simpleTrigger.getClass().getName());
            if (simpleTrigger!=null && simpleTrigger instanceof SimpleTrigger){
      "Found a simple trigger");
    Even though I've modified the RepeatInterval in the configuration loader above.. the trigger is still firing based on the applicationContext.xml configuration. i.e. instead of 150000 the interval is 18000000.

    I guess I cant just modify the interval. I have to somehow "reschedule" it?
    Am I right?

    Last edited by netzone_tech; May 15th, 2006, 10:29 PM. Reason: additional code


    • #3
      Rescheduling Quartz job

      I had just the same need. What I did to acomplish this was:

      add a property to my controller class (Mvc)

      private CronTriggerBean subscriptionExportTriggerBean;

      public void setSubscriptionExportTriggerBean(CronTriggerBean subscriptionExportTriggerBean) {
      this.subscriptionExportTriggerBean = subscriptionExportTriggerBean;

      And add a method which will be called when calling the .htm page

      * Reschedule the Quartz job taking care of exporting the subscription database.
      * @param request
      * @param response
      * @return null
      public ModelAndView rescheduduleSubscriptionExport(HttpServletRequest request, HttpServletResponse response) {
      return null;
      Calendar cal = Calendar.getInstance();
      subscriptionExportTriggerBean.setNextFireTime(cal. getTime());
      return null;



      • #4
        Rescheduling Quartz job

        Have a look at my previous reply