Announcement Announcement Module
Collapse
No announcement yet.
Spring Batch - custom tasklet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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...

  • #2
    How do you plan on importing the CSV into a Map?
    What is your strategy?

    Jeff

    Comment


    • #3
      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
      http://static.springsource.org/sprin...skletStep.html

      S.

      Comment


      • #4
        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.

        Comment


        • #5
          Originally posted by kss View Post
          Thanks for the reply.
          I was wondering though the difference between implementing your own Tasklet and the TaskletStep class ? Is there any documentation on using the TaskletStep class.
          My mistake. I meant Tasklet and not TaskletStep.

          Comment

          Working...
          X