Announcement Announcement Module
No announcement yet.
Running multiple jobs in spring batch admin using REST with same jobname. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Running multiple jobs in spring batch admin using REST with same jobname.

    I am using Spring Batch Admin to run batch jobs for our system. We have to run these jobs many times. I am using the rest interface of spring batch admin. I start a new job using Spring RestTemplate.

    RestTemplate tpl = new RestTemplate();
            tpl.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + "/jobs/myBatchJob;
    This works to start the first job but on subsequent jobs the request does not start a new instance of the job. In the job configuration file I have an jobParmatersIncrementer defined
    <job id="myBatchJob" xmlns=""
    		restartable="true" incrementer="jobParametersIncrementer">
    <bean id="jobParametersIncrementer" class="" />
    I have tried changing my postForLocation to
    List<JobInstance> jobInstances = jobExplorer.getJobInstances("myBatchJob", 0, 30);
                JobParameters jobParameters = jobInstances.get(0).getJobParameters();
                RunIdIncrementer runIdIncrementer = new RunIdIncrementer();
                JobParameters jobParameters = runIdIncrementer.getNext(jobParameters); 
            RestTemplate tpl = new RestTemplate();
            tpl.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + "/jobs/myBatchJob?launch=Launch&{parameters}", "runid", jobParameters.toString());
    It works from the spring batch admin page by clicking the launch button. This is in the parameter edit box

    How do you run a job in Spring Batch Admin from another web application more than once?

  • #2
    I haven't tried with the resttemplate but let me tell you what I tried and worked for me.

    I created a Tasklet which will clear the spring batch tables -> RemoveSpringBatchHistoryTasklet (Courtesy Antoine Rey).

    The tasklet is been added as a new job, since I don't want to interrupt the existing job.

    <job id="clearBatchJob" xmlns="" restartable="true">
        <step id="clearBatchJobStep"> <!-- Step 0 -->
        <!-- Basic step to clear all batch related table entries so that batch job can run again -->
            <tasklet ref="removeSpringBatchHistoryTasklet"/>
    <bean id="removeSpringBatchHistoryTasklet" class="com.myapp.test.tasklet.RemoveSpringBatchHistoryTasklet" />
    Then I ran this job before running the original job.
    RestTemplate restTemplate = new RestTemplate();
        restTemplate.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + "/jobs/{jobName}.json", "name", clearBatchJobName);
        restTemplate.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + "/jobs/{jobName}.json", "name", myBatchJobName);
    I know that this is not the best solution. But this worked for me