SimpleJobLauncher and Queuing
I'm using the SimpleJobLauncher Thread Pool task executor to queue jobs. Let's say, I have three jobs
Code:
<job id="job1">
<step ="jobStep1">
<chunk>
</chunk>
</step>
</job>
<job id ="job2">
<step="jobStep2">
<chunk>
</chunk>
</step>
</job>
<job id="job3">
<step id="jobStep3">
<chunk>
</chunk>
</step>
</job>
I'm using the SimpleJobLauncher class and setting its task executor so that I can queue jobs. Synchronization is required in this
case. Below is my bean definition for the job launcher.
Code:
<beans:bean id="asynchJobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
p:jobRepository-ref="jobRepository">
<beans:property name="taskExecutor">
<beans:bean
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<beans:property name="corePoolSize" value="1" />
<beans:property name="maxPoolSize" value="1" />
<beans:property name="queueCapacity" value="500" />
<beans:property name="keepAliveSeconds" value="600" />
</beans:bean>
</beans:property>
</beans:bean>
I want to chain jobs. Have one job call the next. I don't want to copy step definitions from one job into another. There is a possibility that the chain job will change one day and we'd like to make the change in one place rather than two.
This is what I do NOT want to do to chain jobs.
Code:
<job id="job1">
<step ="jobStep1">
<chunk>....
</chunk>
</step>
<step="jobStep2">
<chunk>....
</chunk>
</step>
</job>
I want do use the ref to another job like this:
Code:
<job id="job1">
<step ="jobStep1">
<chunk>....
</chunk>
</step>
<step="jobStep2">
<job ref="job2"/>
</step>
</job>
However, this messes up the queueing. When I start job 1, it gets put into a STARTED state. I think start Job3 which gets queued. Once Job 1 completes, the queued job starts next, then Job2 runs. I need Job1 and Job2 to complete before running Job3. Can someone assist with how to go about this and still have a minimal amount of code?