Results 1 to 4 of 4

Thread: Quartz - associating JobDataMap with trigger

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    4

    Exclamation 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. #2

    Default 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.

  3. #3
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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>

  4. #4
    Join Date
    Nov 2006
    Posts
    4

    Default 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •