I have two scheduled tasks that I want to run in parallel. These two tasks execute a Spring Batch job. One every 15 seconds and the other ever 3 seconds. The problem is one will be running and the other is blocked until it finishes.
I can't seem to find a similar question or example anywhere. Any ideas? Thanks, /w
Here's a bit of my configuration. I'm using spring-task-3.2 and spring-batch-2.2 with Spring 3.2.
This batch job is ran by the mappingRunScheduler. The other task runScheduler is very similar and no beans are shared.
<job id="mappingJob" xmlns="http://www.springframework.org/schema/batch">
<step id="mappingStep1" next="mappingStep2">
<tasklet>
<chunk reader="mappingItemReader"
processor="mappingItemProcessor"
writer="mappingItemWriter" commit-interval="1" />
</tasklet>
</step>
<step id="mappingStep2">
<tasklet ref="mappingTasklet" />
</step>
</job>
<bean id="mappingTasklet"
class="com.example.repository.batch.MappingTasklet"
scope="prototype">
<constructor-arg index="0" ref="mappingLister" />
</bean>
<bean id="mappingItemWriter"
class="com.example.repository.batch.MappingItemWriter" scope="prototype" />
<bean id="mappingLister"
class="com.example.repository.batch.MappingLister"
scope="prototype">
<constructor-arg index="0" ref="liveRepositoryService" />
</bean>
<bean id="mappingItemProcessor"
class="com.example.repository.batch.MappingItemProcessor"
scope="prototype">
<constructor-arg index="0" ref="liveRepositoryService" />
</bean>
<bean id="mappingItemReader"
class="com.example.repository.batch.MappingItemReader" scope="step">
<constructor-arg index="0">
<value>#{mappingLister.getModifiedList()}</value>
</constructor-arg>
</bean>
<bean id="mappingRunScheduler"
class="com.example.repository.batch.MappingRunScheduler" />
<task:scheduled-tasks>
<task:scheduled ref="runScheduler"
method="run" cron="*/15 * * * * *" />
<task:scheduled ref="mappingRunScheduler"
method="run" cron="*/3 * * * * *" />
</task:scheduled-tasks>
The MappingRunScheduler - runs the batch job.
@Service(value = "mappingRunScheduler")
@Component
public class MappingRunScheduler {
public MappingRunScheduler() {
}
public void run() {
try {
String uuid = new Date().toString() + "-"
+ UUID.randomUUID().toString();
JobParameters param = new JobParametersBuilder()
.addString("uuid", uuid)
.addString("job", "mapper").toJobParameters();
JobExecution execution = jobLauncher.run(job, param);
} catch (JobExecutionAlreadyRunningException
| JobRestartException
| JobParametersInvalidException ex) {
} catch (JobInstanceAlreadyCompleteException ex) {
}
}
}
<task:scheduler />. Overlooked that. - wsams