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

  • Quartz runtime job scheduling

    I need to schedule jobs within Quartz at runtime based on user entered scheduling detail (I build the cron trigger for use within Quartz). I have wired the SchedulerFactoryBean as:
    <bean id="scheduleFactory" class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
    <property name="autoStartup"><value>true</value></property>
    </bean>
    From the API guide, it is suggested that I wire the scheduleFactory to the object that will be manipulating the scheduler... so for example, I wired the scheduleFactory to a controller class so this controller can add the user-defined job and schedule to Quartz. From this class (the controller) I need to add a schedule to Quartz but the scheduleFactory does not expose the Scheduler object from Quartz.

    Within Quartz you would do something like:
    Scheduler sched = scheduleFactory.getScheduler();
    and then work with the sched instance and schedule the job within Quartz like:
    sched.scheduleJob(jobDetail, cronTrigger);
    How can I do the same thing with Spring integration, meaning I would like Spring to manage the ScheduleFactory and all my app code needs to do is feed it schedules (jobDetails and cronTriggers).

    Thanks in advance for your help.

  • #2
    I figured it out.

    Basically, you wire the schedulerFactory then in you implementation class set the property of (instance of) a org.quartz.impl.StdScheduler. Then you use this class instance as the handle to the scheduler.

    Comment


    • #3
      running schedule jobs

      Hi All,
      I require to run a schedule job in spring which checks the attendance of students daily at 10AM in the morning, I have the application context mapping as below,

      <!-- bean definition for Job class -->
      <bean id="StudentRuleProcessor" class="some.RuleProcessor"/>

      <!-- Creates the job -->
      <bean id="attendanceJob" class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
      <property name="targetObject" ref="StudentRuleProcessor"/>
      <property name="targetMethod" value="StudentRuleProcessor"/>
      <property name="concurrent" value="false"/>
      </bean>

      <! - Creates the schedule -->
      <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
      <property name="jobDetail" ref="diabeticJob"/>
      <property name="cronExpression" value="0 0 10 * * ?"/>
      </bean>

      <bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
      <property name="triggers">
      <list>
      <ref bean="cronTrigger"/>
      </list>
      </property>
      </bean>

      and the corresponding class "some.RuleProcessor", but i cannot run it, Please tell me what more to be done the run the same.
      I have already deployed the code in JBoss Server. Is it correct.

      thanks and regards,
      Sudip.

      Comment


      • #4
        The cron expression looks fine, but what's with the cron trigger referencing diabeticJob but you've shown attendanceJob defined?

        Can you re-post the Spring config, and maybe change the cron trigger temporarily to something like 0 0/2 * * * ? , which is every 2 minutes, to see what happens.

        Do you see anything in the log file?

        Comment


        • #5
          Originally posted by derrickhackman
          I figured it out.

          Basically, you wire the schedulerFactory then in you implementation class set the property of (instance of) a org.quartz.impl.StdScheduler. Then you use this class instance as the handle to the scheduler.
          Hi, I believe I have the same requirements as yourself but being a novice in both spring and quartz, do you think you could elaborate a bit more with some sample code? For some reason, there doesn't seem to be any detailed explanation of how to do this; closest is in the api docs for SchedulerFactoryBean whereby it mentions dynamic registration of jobs etc but no detailed explanation as to how this could be done

          Any help would be most appreciated! MTIA

          Comment


          • #6
            Code:
            <!-- scheduler bean for quartz -->
            <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                <property name="quartzProperties">
                    <props>
                        <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
                        <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
                        <prop key="org.quartz.threadPool.threadCount">20</prop>
                    </props>
                </property>
            </bean>
            
            <bean id="foo" class="Foo">
                <property name="scheduler" ref="scheduler"/>
            </bean>
            
            class Foo {
                private org.quartz.Scheduler scheduler;
            
                // the SchedulerFactoryBean is exposed as a quartz scheduler object
                public void setScheduler(Scheduler scheduler) {
                    this.scheduler = scheduler;
                }
            
                public void scheduleAJob() {
                    Trigger trigger = new SimpleTrigger(...);
                    JobDetail job = new JobDetail(...);
                    scheduler.scheduleJob(job, trigger);
                }
            }

            Comment

            Working...
            X