Reputation: 433
as of now i am running spring batch with single job. then now i want to run multiple jobs which is different to each other means different functionality. in my configuration file i configured two jobs with different id and different names. now i have to run those jobs. can you please tell me how can i run. here my doubt is in my java class i have written this code for run the batch.
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
CompositeWriter compositeWriter=new CompositeWriter();
JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters();
Long startTime=System.nanoTime();
JobExecution execution = jobLauncher.run(job, jobParameters);
for other job how can i call the run method of jobLauncher.
and my configuration file is
<bean id="pagingItemReader" class="com.tcs.UserRowMapper">
</bean>
<job id="testJob" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk reader="pagingItemReader" processor="testApp" writer="itemWriter"
commit-interval="1" />
</tasklet>
</step>
</job>
<job id="testJob2" xmlns="http://www.springframework.org/schema/batch">
<step id="step2">
<tasklet>
<chunk reader="itemReaderForNotification" processor="processforNoticeHeader" writer="itemUpateForNoticeHeader"
commit-interval="1" />
</tasklet>
</step>
</job>
Upvotes: 2
Views: 9821
Reputation: 73
Your posted code seems incomplete; but you can just get the job from the config by its id, no ? Something like this :
ApplicationContext context = new ClassPathXmlApplicationContext(config);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job1 = (Job) context.getBean("testJob");
Job job2 = (Job) context.getBean("testJob2");
JobExecution execution1 = jobLauncher.run(job1, new JobParameters());
System.out.println("Exit Status : " + execution1.getStatus());
JobExecution execution2 = jobLauncher.run(job2, new JobParameters());
System.out.println("Exit Status : " + execution2.getStatus());
Upvotes: 2