Aug 3rd, 2012, 01:35 PM
Spring Batch - custom tasklet
I have a Spring Batch job with sequence of Steps (with ItemReader, an optional ItemProcessor, ItemWriter). There are multiple Steps but the most use FlatFileItemReader/Writer to read in a CSV file and do some operations based on the item (single row read).
Now I need to have to read in the CSV file (as a whole) and create a Map object that I need in batch Steps. I was thinking of having a custom Tasklet to do this (read in the CSV file and create the map to put in Execution Context which can be later read in the Steps). I was wondering if this is a good solution for this ? If anybody has done something similar would appreciate any inputs...
Aug 4th, 2012, 05:49 PM
How do you plan on importing the CSV into a Map?
What is your strategy?
Aug 5th, 2012, 02:57 AM
Careful with execution contexts. The step execution context is flushed at every transaction commit so it could have a severe impact in case your map contains a lot of data. Job execution context may be a better fit for this even though you have to be aware that the content of your map will be serialized back in the execution context table.
If the CSV file is small, you can indeed create a simple tasklet that won't go through the processing of reading/processing/writing (you can consider this as a pre-processor of your job). We actually use that a lot to "prepare" the job and making sure it will be able to run properly in a given environment.
Please have a look to TaskletStep
Aug 6th, 2012, 08:16 AM
Thanks for the reply.
Yes so the map for my spring batch job is not going to have a lot of data (just short strings). Currently I am following the approach in reference doc to put the map in Step Execution Context in my custom tasklet (implementing Tasklet interface) and then promote to Job Execution Context (ExecutionContextPromotionListener). This seems to work fine..
I was wondering though the difference between implementing your own Tasklet and the TaskletStep class ? Is there any documentation on using the TaskletStep class.
Aug 6th, 2012, 09:42 AM
My mistake. I meant Tasklet and not TaskletStep.
Originally Posted by kss
Tags for this Thread