Announcement Announcement Module
No announcement yet.
How to loop on a step ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to loop on a step ?

    Hi all,

    Evreything is in the is it possible to loop on a step ?
    I've got a list of item which are processed through a step (reader, processor, writer).
    But these list is itself contained in an item which belongs to a list too.
    so, I'd like to loop on this list and execute my step for each elements.

    Is there a way to do that ? I saw something called "RepeatTemplate, RepeatCallBack, RepeatOperations" in the documentation. But I did not manage to understand how it works.
    Is it possible to read a step ?
    How should I configure this in the context.xml ?

    Thanks a lot for helping me !

  • #2

    The other option is write a JobLauncher that loops through items in the outer list and launches a job for each one. Then you could use the ItemReader to read items from the inner list.

    It really depends on whether you need to be able to skip individual inner-list items or if skipping an entire outer-list item is ok.


    • #3
      Thanks for your answer.

      Actually, I need to be able to skip each individual inner-list items.
      That's why I thought that I could configure my step for the inner list. And then, loop on this step for each element of the outter list.
      And, it seems that it is not possible so easily ? right ?


      • #4
        This problem is that you can only skip an "item" where an "item" is the thing returned from an ItemReader. So i would suggest that you put the loop in the JobLauncher and launch a job for each outer-list item.


        • #5
          Ok, I'll try that. But the documentation does not provide lot of information about the JobLauncher. Is there a link where I could find more information ?

          Moreover, just one more question, if I cannot repeat my step. What's the aim of the RepeatTemplate ?

          Thank for your help.


          • #6
            For the JobLaucher, you should just copy the SimpleJobLaucher and modify it to fit your needs.

            As for the RepeatTemplate, there is looping happening: at the job-level over steps and at the step-level over items. There just isn't looping at a level below that.


            • #7
              I'm trying to implement what you said. But, actually, there still is a problem with this solution.
              How can I provide my outer-list to the job launcher as it is not provided as a parameter.

              Here is the process I need (maybe I was not clear enough)
              1) Call to a service which provides the outer-list
              2) Iteration on this outer-list (L1)
              3) For each item, call to a service with L1 item as a parameter
              4) Get the inner-list from each item of the outer-list
              5) Iteration on this inner-list (L2)
              6) For each item, call to a service with L2 item as a parameter
              7) Call to a service with L1 item as a parameter

              So, looping in the JobLauncher will help for steps 2 to 7. But what about the step 1 ?
              Where could I call my service ? I don't know...


              • #8
                You can call the service from the JobLauncher


                • #9
                  mmmmh...true !
                  Sorry, this, I could have found it by myself. I'm wondering so many questions that I even don't see the evidence...

                  Thanks !


                  • #10
                    By the way, do you think that, by modifying the task executor, it would be possible to process these jobs in parallel threads ?


                    • #11
                      You should be able to use an asynchronous task executor to run them in parallel.


                      • #12
                        Ok, that's great !

                        Last question (I hope ). If I understand, I have two create two jobs.
                        The first one will be the one launched by the JobLauncher during the loop.
                        The second one will be the one called in command line for launching the process. Am I right ?

                        Then, the second job will do nothing I guess as everything will be done in the JobLauncher et the other jobs.
                        So, does SpringBatch allows me to create an empty job such as:
                        <batch:job id="myEmptyJob" />
                        <batch:job id="myUsefulJob">
                           <batch:step id="myStep">