TV Nath
TV Nath

Reputation: 490

Spring Quartz Scheduler - Run job after the other has completed

I have two jobs configured as cronTriggerBeans. They are added to a quartz SchedulerFactoryBean. They run at different times but modify same set of data in a database. Problem occurs on particular occasions when the job running time is the same. In this scenario, I want job2 to wait for job2 to be completed. I realize there is a way to implement this scenario if it's the case every single time. But in my case, one job runs every 1 hour and the other every 24 hours. So when the 24 hours job run, I want to have the hourly job to be finished. How can I achieve it.

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
        <property name="triggers">
            <list>
                <ref bean="hourlyJob"/>
                <ref bean="twentyFourHourlyJob"/>
            </list>
        </property>
    </bean>

<bean id="hourlyJob" class="org.springframework.scheduling.quartz.CronTriggerBean">
       // bean configurations

<bean id="twentyFourHourlyJob" class="org.springframework.scheduling.quartz.CronTriggerBean">
        // bean configurations
    </bean>   

Upvotes: 2

Views: 2214

Answers (1)

m.aibin
m.aibin

Reputation: 3593

You can use Job Step to configure flow and for example run the second job after finishing the other method or run it directly from the body from the first job.

Look here: http://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html#external-flows

Upvotes: 1

Related Questions