Hi,
I have scheduled the job inside the Batch admin in the following method
I have given the time to start in the properties fileCode:@Service public class JobRunner { @Autowired private JobLocator jobLocator; @Autowired private JobLauncher jobLauncher; @Scheduled(cron="${preparis.refresh.cron}") public void runMyJob() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addDate("currentTime", new Date()).toJobParameters(); JobExecution exec = jobLauncher.run(jobLocator.getJob("preparisJob"), jobParameters); } }
Following is my job.xml.
When the job runs it is executing it twice rather than once. I am not sure why it is doing that? I get two execution id for each step. I have tried to debug through but no matter what each step activePeopleLoad and InactivePeopleLoad gets executed twice.Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <description>Preparis updating users.</description> <import resource="classpath:/META-INF/spring/batch/override/data-source-context.xml" /> <context:annotation-config /> <context:component-scan base-package="com.duanemorris.batch"></context:component-scan> <tx:annotation-driven/> <task:annotation-driven /> <batch:job id="preparisJob" restartable="false" incrementer="jobParametersIncrementer"> <batch:step id="activePeopleLoad" next="inactivePeopleLoad"> <batch:tasklet> <batch:chunk reader="activePeopleItemReader" writer="activePeopleItemWriter" skip-limit="2" commit-interval="2000"> <batch:skippable-exception-classes > <batch:include class="java.lang.RuntimeException"/> </batch:skippable-exception-classes> </batch:chunk> </batch:tasklet> </batch:step> <batch:step id="inactivePeopleLoad" > <batch:tasklet> <batch:chunk reader="inactivePeopleItemReader" writer="inactivePeopleItemWriter" skip-limit="2" commit-interval="2000"> <batch:skippable-exception-classes > <batch:include class="java.lang.RuntimeException"/> </batch:skippable-exception-classes> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <bean id="personDAO" class="com.duanemorris.dao.dminfo.MainlistFullDAO"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="personWorkInfoDAO" class="com.duanemorris.dao.dminfo.PersonWorkInfoDAO"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="personManager" class="com.duanemorris.bo.dminfo.managers.impl.MainlistManagerImpl"> <property name="dao" ref="personDAO" /> </bean> <bean id="personWorkInfoManager" class="com.duanemorris.bo.dminfo.managers.impl.PersonWorkInfoManagerImpl"> <property name="workInfoDao" ref="personWorkInfoDAO" /> </bean> <bean id="activePeopleItemReader" class="com.duanemorris.batch.preparis.MainlistPeopleItemReader"> <property name="personManager" ref="personManager" /> <property name="personWorkInfoManager" ref="personWorkInfoManager" /> <property name="status"> <list> <value>Active</value> <value>Pending Active</value> </list> </property> </bean> <bean id="inactivePeopleItemReader" class="com.duanemorris.batch.preparis.MainlistPeopleItemReader"> <property name="personManager" ref="personManager" /> <property name="personWorkInfoManager" ref="personWorkInfoManager" /> <property name="status"> <list> <value>Inactive</value> <value>Deceased</value> <value>Retired</value> <value>Terminated</value> </list> </property> <property name="company"> <list> <value>20</value> </list> </property> <property name="terminatedDate" value="10" /> </bean> <bean id="activePeopleItemWriter" class="com.duanemorris.batch.preparis.ActivePeopleItemWriter" /> <bean id="inactivePeopleItemWriter" class="com.duanemorris.batch.preparis.InActivePeopleItemWriter" /> <bean id="jobParametersIncrementer" class="org.springframework.batch.admin.sample.TrivialJobParametersIncrementer"/> </beans>
Code:stepName: inactivePeopleLoad stepSummary: StepExecution: id=204, version=3, name=inactivePeopleLoad, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0 End of job ID: 126 End of jobJobInstance: id=126, version=0, JobParameters=[{currentTime=1301941845803}], Job=[preparisJob] stepName: inactivePeopleLoad stepSummary: StepExecution: id=205, version=3, name=inactivePeopleLoad, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0 End of job ID: 127 End of jobJobInstance: id=127, version=0, JobParameters=[{currentTime=1301941873896}], Job=[preparisJob]


Reply With Quote