Quartz with Spring: more jobs with different input argument

Discussion in 'Java' started by Alessandro, Apr 26, 2010.

  1. Alessandro

    Alessandro Guest

    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
    }
    }
     
    Alessandro, Apr 26, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hardikh2000

    JOBs............JOBs............JOBs

    hardikh2000, Aug 16, 2005, in forum: Python
    Replies:
    0
    Views:
    444
    hardikh2000
    Aug 16, 2005
  2. rmn190
    Replies:
    2
    Views:
    2,460
    Arne Vajhøj
    Jan 10, 2008
  3. Goldfish
    Replies:
    1
    Views:
    819
    Goldfish
    Nov 6, 2008
  4. nicky boy
    Replies:
    0
    Views:
    722
    nicky boy
    Feb 7, 2009
  5. Alessandro

    Spring and 2 Quartz job running

    Alessandro, Feb 25, 2009, in forum: Java
    Replies:
    0
    Views:
    784
    Alessandro
    Feb 25, 2009
Loading...

Share This Page