I have a spring batch job which is processing data similar to below. I have a requirement to aggregate the values for each key, and then use that summed value in a final processor. I can't control the order of the data received.
Key - Value
A - 1
A - 5
A - 2
B - 2
B - 2
B - 2
C - 1
A - 2
..
..
..
B - 4
X - 10
I have setup a pre-processor, which takes each row and checks the StepExecutionContext
for an existing aggregated value for the key. It creates a new one or amends an existing one if not. At the end of this step all key values must have been aggregated.
My second processor then checks for distinct key names, and it attempts to read the aggregated value from the StepExecutionContext
. Of course the aggregated values are not present in the second processor's StepExecutionContext
.
In another thread I've read that I should use a ExecutionContextPromotionListener
to promote the StepExecutionContext from my first processor to the JobExecutionContext
which would make them available to the second process. I know the ExecutionContextPromotionListener takes a list of key names to promote, but in my case I don't know the list of keys to promote until the end of the first processor. Can anybody suggest a workaround?