Announcement Announcement Module
Collapse
No announcement yet.
Rescheduling Quartz job Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
            <!-- 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>
                    <property name="startDelay"><value>5000</value></property>
                    <property name="repeatInterval"><value>1</value></property>
                    <property name="repeatCount"><value>0</value></property>
            </bean>
    Code:
            <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">^M
                    <property name="triggers">^M
                            <list>^M
                                    <ref local="cronTrigger"/>^M
                                    <ref local="simpleTrigger"/>^M
                            </list>^M
                    </property>^M
            </bean>

    Thanks.

  • #2
    hmm..

    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:

    Code:
    <bean id="performanceExtractorService" class="com.bla.advance.performance.webapp.service.impl.PerformanceExtractorServiceImpl" singleton="false">
            <property name="emailService" ref="emailService"/>
        </bean>
    
        <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>
    
      <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"/>
        </bean>
    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":


    Code:
    public class ConfigurationLoader {
    ...
    ..
    .
      Object simpleTrigger = wac.getBean("simpleTrigger");
            logger.info("bean is of type " + simpleTrigger.getClass().getName());
            if (simpleTrigger!=null && simpleTrigger instanceof SimpleTrigger){
                logger.info("Found a simple trigger");
                ((SimpleTriggerBean)simpleTrigger).setRepeatInterval(150000);
            }
    ..
    ..
    
    
    }
    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?




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

    Comment


    • #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) {
      if(!validHost(request)){
      return null;
      }
      Calendar cal = Calendar.getInstance();
      cal.add(Calendar.SECOND,10);
      subscriptionExportTriggerBean.setNextFireTime(cal. getTime());
      return null;
      }



      Geir

      Comment


      • #4
        Rescheduling Quartz job

        Have a look at my previous reply

        Geir

        Comment

        Working...
        X