- JOB にパラメータを与える
- JSL(Job Specification Language)
<?xml version="1.0" encoding="UTF-8"?>
<job id="param-job"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
version="1.0">
<properties>
<property name="work_dir" value="/opt/batch"/>
</properties>
<step id="sample-batchlet">
<properties>
<property name="api_version" value="V20L13"/>
</properties>
<batchlet ref="ParamBatchlet"/>
</step>
</job>
- 実行時パラメータ
JobOperator job = BatchRuntime.getJobOperator();
Properties prop = new Properties();
prop.setProperty("work_file", UUID.randomUUID().toString());
long id = job.start("param-job", prop);
- Batchlet からの取得方法
package com.mycompany.jbatchexam;
import java.util.Properties;
import javax.batch.api.Batchlet;
import javax.batch.runtime.BatchRuntime;
import javax.batch.runtime.context.JobContext;
import javax.batch.runtime.context.StepContext;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.inject.Named;
@Dependent
@Named("ParamBatchlet")
public class ParamBatchlet implements Batchlet {
@Inject
private JobContext jobCtx;
@Inject
private StepContext stepCtx;
@Override
public String process() throws Exception {
Properties jobProp = jobCtx.getProperties();
System.out.println("JOB PARAM=" + jobProp);
Properties stepProp = stepCtx.getProperties();
System.out.println("STEP PARAM=" + stepProp);
Properties runtimeParam = BatchRuntime.getJobOperator().getParameters(jobCtx.getExecutionId());
System.out.println("RUNTIME PARAM=" + runtimeParam);
return null;
}
@Override
public void stop() throws Exception {
}
}
- 実行結果
情報: Batch Start
情報: Batch Queued 25
情報: JOB PARAM={work_dir=/opt/batch}
情報: STEP PARAM={api_version=V20L13}
情報: RUNTIME PARAM={work_file=2d7f1178-aa02-4451-a359-241347b50c96}
- 実行時パラメータを Execution ID から取得していることに注意