We are trying to implement a batch job using spring batch partitioning.In this in "step 2" is a partitioned step where I need some data from step 1 for processing.I used StepExecutionContext which will be promoted to job Execution Context at step1 to store this data.
I tried to use @BeforeStep annotation in partitioner class to get the stepExecutionContext from which I can extract the data stored previously and put it in ExecutionContext of the partitioner .But the method with @BeforeStep annotation is not getting invoked in the partitioner.
Is there any other way to achieve this.
Partitioner Implementation
public class NtfnPartitioner implements Partitioner {
private int index = 0;
String prev_job_time = null;
String curr_job_time = null;
private StepExecution stepExecution ;
ExecutionContext executionContext ;
@Override
public Map<String, ExecutionContext> partition(int gridSize)
{
System.out.println("Entered Partitioner");
List<Integer> referencIds = new ArrayList<Integer>();
for (int i = 0; i < gridSize;i++) {
referencIds.add(index++);
}
Map<String, ExecutionContext> results = new LinkedHashMap<String,ExecutionContext>();
for (int referencId : referencIds) {
ExecutionContext context = new ExecutionContext();
context.put("referenceId", referencId);
context.put(NtfnConstants.PREVIOUS_JOB_TIME, prev_job_time);
context.put(NtfnConstants.JOB_START_TIME, curr_job_time);
results.put("partition." + referencId, context);
}
return results;
}
@BeforeStep
public void beforeStep(StepExecution stepExecution) {
// TODO Auto-generated method stub
System.out.println("Entered Before step in partion");
JobExecution jobExecution = stepExecution.getJobExecution();
ExecutionContext jobContext = jobExecution.getExecutionContext();
System.out.println("ExecutionContext"+jobContext);
String prev_job_time = (String) jobContext.get(NtfnConstants.PREVIOUS_JOB_TIME);
String curr_job_time = (String) jobContext.get(NtfnConstants.JOB_START_TIME);
}
NtfnPartitioner
as listener in your xml? – Ningpo