Data Transfer Between Steps

When a job consists of multiple steps, data can be transferred between steps for processing. The following describes how to transfer data between steps.

  • BeforeStep

To transfer data between steps, you must store the data to be transferred in the ExecutionContext of JobExecution. The ExecutionContext of JobExecution can be obtained in the beforeStep method and, if necessary, can be defined and used as in the example below. Note that beforeStep cannot be used in a Tasklet.

  • Caution

(1) beforeStep is a step pre-process method that is called before a step is executed, and business logic must not be included in this method.

private ExecutionContext jobExecutionContext; // (1)

// (2)
@BeforeStep
public void beforeStep(StepExecution stepExecution)
{
    jobExecutionContext = stepExecution.getJobExecution().getExecutionContext();
}

(1) Declare ExecutionContext as a member variable in the batch bean in order to use ExecutionContext.

(2) Define the beforeStep method to obtain the ExecutionContext of JobExecution, and set the ExecutionContext of JobExecution from StepExecution to the ExecutionContext in (1) that was declared as a member variable.

  • ExecutionContext

ExecutionContext can be used as follows.

jobExecutionContext.putString("inptDate", inptDate); // (1)

/* ExecutionContext Get */
String inptDate;
if(jobExecutionContext.containsKey("inptDate")) {  // (2)
    inptDate = jobExecutionContext.getString("inptDate");  // (3)
}
else {
    // Key not found
}

(1) Set the value to be configured in ExecutionContext.

(2) Check whether the key set in ExecutionContext exists. If you try to get a key that does not exist, an exception occurs, so it is necessary to check whether the key exists.

(3) Get the value configured in ExecutionContext.

  • Data Transfer Between Steps in Tasklet

In a Tasklet, this can be handled not in BeforeStep but in the execute method, which is the Tasklet implementation method.

@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext)
        throws Exception {

    ExecutionContext jobExecutionContext =
        chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext();
SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.