Announcement Announcement Module
Collapse
No announcement yet.
Problem launching batch job (async) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem launching batch job (async)

    I have been trying to develop a proof-of-concept for async processing. I have a fairly simple scenario. My Job uses a custom tasklet that makes a service call. When I launch the job, I get an exception saying the Job is already running, however it is strange because it specifies the job id=0.
    Here is exception:
    org.springframework.batch.core.repository.JobExecu tionAlreadyRunningException: A job execution for this job is already running: JobInstance: id=0, version=0, JobParameters=[{}], Job=[myJob]

    Any ideas would be appreciated.

    I am using this to launch my job (stripped down):
    @Component
    public class MyAsyncDelegate {
    @Autowired
    JobLauncher jobLauncher;

    @Autowired
    @Qualifier("myJob")
    Job job;

    @Async
    public Future<MyResponse> callServiceAsync(
    MyRequest request) throws Exception {

    SendWithRetryTemplateTasklet tasklet = SpringUtil
    .getBeanFactory().getBean(
    SendWithRetryTemplateTasklet.class);
    tasklet.setRequest(request);
    JobExecution jobExecution = jobLauncher.run(job, new JobParameters());

    return null;
    }
    }

    This is my configuration (Also stripped down):
    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor">
    <bean class="org.springframework.core.task.SimpleAsyncTa skExecutor" />
    </property>
    </bean>
    <batch:job-repository id="jobRepository"
    transaction-manager="transactionManager" />
    <batch:job id="myJob">
    <batch:step id="myStep">
    <batch:tasklet ref="sendWithRetryTemplateTasklet">
    </batch:tasklet>
    </batch:step>
    </batch:job>
    Last edited by gpontecorvo; Oct 5th, 2011, 12:22 PM.

  • #2
    Each time you launch a job a new instance needs to be created, unless the job is another execution of the instance due to unsuccessful status in the previous run. The uniqueness of job instance in determined by the job parameters. Since you are passing the same parameter you cannot execute the same job as the previously launched instance is already running. To resolve this issue pass different parameters which will make each launch a new instance. If your parameters are not unique you can look at JobParametersIncrementer to create uniqueness.

    Comment


    • #3
      Thank you for your guidance. When I properly specified my Tasklet with task-executor and transaction-manager attributes, and used the RunIdIncrementer implementation of JobParametersIncrementer, I got things working. My next challenge is to figure out how to populate the BATCH_JOB_EXECUTION_CONTEXT table withe request/response information from each execution.

      Comment

      Working...
      X