From: Alessandro on
Hi all,

I've used Spring + Quartz some times, but in this case I need to call the
same job more times a day, passing it as input a different text file (e.g.
cycle1.txt, cycle2.txt and so on).
What could be the best solution ?

This is my idea:

//spring xml file
....
<!-- CYCLE 1 -->
<bean class="org.springframework.scheduling.quartz.JobDetailBean"
id="jobCycle1">
<property name="jobClass" value="MyJob"></property>
<property name="jobDataAsMap">
<map>
<entry key="inputFile" value="cycle1.txt"></entry>
</map>
</property>
</bean>
<bean id="cycle1Trigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobCycle1"></property>
<property name="cronExpression" value="00 00 09-12 * * ? *"></property>
</bean>

<!-- CYCLE 2 -->
<bean class="org.springframework.scheduling.quartz.JobDetailBean"
id="jobCycle2">
<property name="jobClass" value="MyJob"></property>
<property name="jobDataAsMap">
<map>
<entry key="inputFile" value="cycle2.txt"></entry>
</map>
</property>
</bean>
<bean id="cycle2Trigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobCycle2"></property>
<property name="cronExpression" value="00 00 13-16 * * ? *"></property>
</bean>

<!-- MORE CYCLES NEEDED - TO BE ADDED -->

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cycle1Trigger" />
<ref bean="cycle2Trigger" />
</list>
</property>
</bean>
....

//job class
public class MyJob extends QuartzJobBean implements StatefulJob{
String inputFile;

private void setInputFile(String inputFile){
this.inputFile = inputFile;
}


@Override
protected void executeInternal(JobExecutionContext ctx)
throws JobExecutionException {
core(inputFile);
}

private static core(String inputFile){
//my business logic
}
}