Announcement Announcement Module
Collapse
No announcement yet.
Quartz - associating JobDataMap with trigger Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz - associating JobDataMap with trigger

    I'm a new Spring user so please forgive my ignorance if what I ask may be trivial or basic. In my applicationContext.xml, I would like to define one job and associate multiple triggers with that job. The motivation behind this is to define custom attributes for triggers and at the same time using common metadata defined at the job level. The following syntax is more than likely incorrect, but really illustrates what I need.

    <bean name="hfsIndexJob" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass" value="com.haydrian.mgmt.struts.util.HfsIndexingJo b"/>
    <property name="jobDataAsMap">
    <map>
    <entry key="timeToLive" value="3600000"/>
    </map>
    </property>
    </bean>

    <bean id="cronTriggerHfsIndex" class="org.springframework.scheduling.quartz.CronT riggerBean">
    <property name="jobDetail" ref="hfsIndexJob"/>

    <!-- run every night at 9:15 PM -->
    <property name="cronExpression" value="0 15 21 * * ?"/>
    <!-- I want to be able to extend the JobDataMap so that the trigger sees these additional properties. I don't think this is the correct syntax though -->
    <property name="jobDataAsMap">
    <map>
    <entry key="dailyIndexingScript" value="/svt/apps/hfs/daily_reindex.sh"/>
    <entry key="weeklyIndexingScript" value="/svt/apps/hfs/weekly_reindex.sh"/>
    <entry key="dayOfWeekToRunWeeklyJob" value="7"/>
    </map>
    </property>
    </bean>

  • #2
    More JobDetailBeans needed

    Create a new JobDetailBean (or two, three ....) with same JobClass and create a new Crontrigger for this bean. In this new JobDetailBean you can give more values in JobDataMap. So you have two Triggers with different JobData using same JobClass.
    JobDetailBean will be triggered through a Crontrigger --> JobDetailBean creates new Instance of configured JobClass and puts JobData in this created instance (so you has to have setter-methods for this values).
    After that, execute the Job.
    Thatīs it.

    Comment


    • #3
      How about this (note the merge="true" in the child bean - a 2.0 feature I think)?

      Code:
         
      <bean name="hfsIndexJob" class="org.springframework.scheduling.quartz.JobDetailBean" abstract="true">
            <property name="jobClass" value="com.haydrian.mgmt.struts.util.HfsIndexingJob"/>
            <property name="jobDataAsMap">
               <map merge="true">
                  <entry key="timeToLive"  value="3600000"/>
               </map>
            </property>
         </bean>
      
         <bean id="cronTriggerHfsIndex" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <!-- run every night at 9:15 PM -->
            <property name="cronExpression" value="0 15 21 * * ?"/>
      <!-- I want to be able to extend the JobDataMap so that the trigger sees these additional properties. I don't think this is the correct syntax though -->
            <property name="jobDetail">
               <bean parent="hfsIndexJob">
                  <property name="jobDataAsMap">
                     <map merge="true">
                        <entry key="dailyIndexingScript"     value="/svt/apps/hfs/daily_reindex.sh"/>
                        <entry key="weeklyIndexingScript"    value="/svt/apps/hfs/weekly_reindex.sh"/>
                        <entry key="dayOfWeekToRunWeeklyJob" value="7"/>
                     </map>
                  </property>
               </bean>
            </property>
         </bean>

      Comment


      • #4
        Quartz trigger - setting up run-time params - THANKS!!

        Thanks very much for your help. I apologize for taking so long to respond. This did work very well.

        Comment

        Working...
        X