SpringBatch CommandLineJobRunner -next using old run.id

♀尐吖头ヾ 提交于 2019-12-11 04:21:36

问题


We are using the CommandLineJobRunner to execute Spring Batch jobs. We are using -next on the command line:

java -Dlog4j.configuration=file:./prop/log4j.properties -Dlogfile=logfile_load_data -jar EtlLoadData.jar loaddata_etl_config.xml loaddata_etl_job -next

We started coming down with an error:

Job Terminated in error: A job instance already exists and is complete for parameters={run.id=10}.  If you want to run this job again, change the parameters. 

org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={run.id=10}.  If you want to run this job again, change the parameters.
    at  org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:168)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy14.createJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:111)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)

I thought that if you were running with the -next option, this shouldn't be an issue. Any ideas?

As a temporary workaround, I cleaned up the SpringBatch table in the database, but I don't want this to happen again.


回答1:


not aware of a -next option.

quickest way is to pass in the the current timestamp as a parameter to your job. that way it will be unique and won't really interfere with your job.




回答2:


With de -next option, you should set a JobParametersIncrementer Implementation,

in this example i use -> new RunIdIncrementer to avoid the message : A job instance already exists and is complete for parameters

@Autowired
private JobBuilderFactory jobs;
...
@Bean(name=JOB_NAME)
public Job job() {        

    return jobs.get(JOB_NAME)
               .start(this.login())
               .next(this.launchDuke())
               .incrementer(new RunIdIncrementer())
               .build();
}


来源:https://stackoverflow.com/questions/12976662/springbatch-commandlinejobrunner-next-using-old-run-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!