Accesing JobContext from a partitioned step in JSR 352

无人久伴 提交于 2019-12-03 15:38:42

You could try something like this which should conform with the current spec programming model.

Store the object from your first step using the persistent step data in your NormalBatchlet:

stepCtx.setPersistentUserData(mySerializableData);

Retrieve the data from the first step in your partitions, by looking up the previous step:

Long execId = jobCtx.getExecutionId();

List<StepExecution> stepExecs = jobOperator.getStepExecutions(execID);

MyPersistentUserData myData;

for (StepExecution step : stepExecs) {
    if (step.getStepName().equals("somePreviousStepX") {
        myData = (MyPersistentUserData)step.getPersistentUserData();
    }
}

//use myData

There is not a spec-defined way to share the transient user data between the JobContext of the main thread and the partition-level JobContext(s). This is an understandable point of confusion, but this is indeed the intended design.

In specification mentioned an only one way to access to Context - Injection. See paragraph 9.4.1.

"9.4.1 Batch Contexts

Batch artifact access to batch contexts is by injection using the standard @Inject annotation (javax.inject.Inject). A field into which a batch context is injected must not be static and must not be final.

E.g.:

@Inject JobContext _jctxt;

@Inject StepContext _sctxt;

The batch runtime is responsible to ensure the correct context object is injected according to the job or step currently executing."

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