从Jberet userguide可以理解,可以动态构建作业来替代静态xml,但是该指南对如何执行作业构建没有任何投入,因此愿意了解如何执行作业。
Job job = new JobBuilder(jobName)
.restartable(false)
.property("jobk1", "J")
.property("jobk2", "J")
.listener("jobListener1", new String[]{"jobListenerk1", "#{jobParameters['jobListenerPropVal']}"},
new String[]{"jobListenerk2", "#{jobParameters['jobListenerPropVal']}"})
.step(new StepBuilder(stepName)
.properties(new String[]{"stepk1", "S"}, new String[]{"stepk2", "S"})
.batchlet(batchlet1Name, new String[]{"batchletk1", "B"}, new String[]{"batchletk2", "B"})
.listener("stepListener1", stepListenerProps)
.stopOn("STOP").restartFrom(stepName).exitStatus()
.endOn("END").exitStatus("new status for end")
.failOn("FAIL").exitStatus()
.nextOn("*").to(step2Name)
.build())
.step(new StepBuilder(step2Name)
.batchlet(batchlet1Name)
.build())
.build();
最佳答案
简而言之,您可以使用以下方法来启动使用Java JSL创建的作业:
org.jberet.operations.AbstractJobOperator#start(org.jberet.job.model.Job, java.util.Properties)
1.3.0 Beta版
由于Java JSL是一项附加功能,因此您将需要获得JobOperator的JBeret实现并调用上述start方法:
import org.jberet.job.model.Job;
import org.jberet.operations.JobOperatorImpl;
import org.jberet.spi.JobOperatorContext;
JobOperatorImpl jobOperator = (JobOperatorImpl) JobOperatorContext.getJobOperatorContext().getJobOperator();
Job job = new JobBuilder(jobName)
.step(new StepBuilder(stepName)
.reader(...)
.writer(...)
.build())
.build();
Properties params = null;
long jobExecutionId = jobOperator.start(job, params);
版本1.2.0-最终版
JobOperatorImpl jobOperator = (JobOperatorImpl) BatchRuntime.getJobOperator();
Properties jobProperties = new Properties();
long jobExecutionId = jobOperator.start(job, jobProperties);
有关更多详细信息,请参见JBeret sample app javaJSL和代码how to get JBeret job operator。