Java EE JSR 352 - Jberet动态作业生成器和执行

时间:2017-06-19 11:27:40

标签: java java-ee-7 jsr352 jberet

从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();

1 个答案:

答案 0 :(得分:1)

简而言之,您使用以下方法启动使用Java JSL创建的作业:

org.jberet.operations.AbstractJobOperator#start(org.jberet.job.model.Job, java.util.Properties)

版本1.3.0测试版

由于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