PDA

View Full Version : Quartz - associating JobDataMap with trigger



vkarai
Nov 2nd, 2006, 11:58 AM
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.JobDetailBea n">
<property name="jobClass" value="com.haydrian.mgmt.struts.util.HfsIndexingJob"/>
<property name="jobDataAsMap">
<map>
<entry key="timeToLive" value="3600000"/>
</map>
</property>
</bean>

<bean id="cronTriggerHfsIndex" class="org.springframework.scheduling.quartz.CronTriggerB ean">
<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>

bellmann29
Nov 7th, 2006, 05:24 AM
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.

Dave Syer
Nov 7th, 2006, 06:19 AM
How about this (note the merge="true" in the child bean - a 2.0 feature I think)?



<bean name="hfsIndexJob" class="org.springframework.scheduling.quartz.JobDetailBea n" 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.CronTriggerB ean">
<!-- 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>

vkarai
Mar 25th, 2007, 04:42 PM
Thanks very much for your help. I apologize for taking so long to respond. This did work very well.