Your job should know which file to process before executing it. For instance. the file name should be passed as a job parameter. Remove JobExecutionListener and add StepExecutionListener to access job parameters via StepExecution#getJobParameters() . One job = one file.
Now from your scheduler you want to make sure that only one task is executed at a time. You can achieve this in two ways:
• Using the async task executor. In this case, every time you run a task, it will not run in the background (unless your scheduler fires timer events every time in a new thread).
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> <property name="taskExecutor" ref="taskExecutor" /> </bean> <bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
• If you use the same launcher for other tasks that need to be run in the background, you need to use ThreadPoolTaskExecutor , but you can manually check if the task is running:
for (final JobInstance jobInstance : jobExplorer.getJobInstances(jobName(), 0, LOOK_BEHIND_INSTANCES)) { for (final JobExecution jobExecution : jobExplorer.getJobExecutions(jobInstance)) { final BatchStatus status = jobExecution.getStatus(); if (status.isRunning()) {
dma_k source share