Quartz with Spring: more jobs with different input argument

A

Alessandro

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
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top