0

i want to ask you guys if there is a way to make a spring batch always be running and doing the same step over and over again but with a time lapse between this loops if the reader didn't find anything to do. for example my spring batch read from database then do some updates on the list i got from my database. now i want this spring batch to do the same thing again, if he found new lines in database he will do the update otherwise he should wait some seconds then do the same read again and again. My solution is this it works but i don't know if its the best practice to do. i made my step call itself in the next step with causes an infinite loop. then in my reader if he found data from database he will continue processing otherwise i'm doing a thread.sleep().

    <job id="jobUpdate" xmlns="http://www.springframework.org/schema/batch">


        <step id="updates" next="updates">
        <tasklet>
            <chunk reader="reader.." processor="processor..."
                writer="writer..." commit-interval="1" />
        </tasklet>
    </step>
            
</job>


// my reader waiting code if the list is empty.
        if(myList.isEmpty()) {
            try {
                Thread.sleep(constantes.WAIT_TIME_BATCH_RERUN);
                System.out.println("im sleeping");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
Abdel
  • 53
  • 5
  • The following threads should help: https://stackoverflow.com/questions/29286699/repeating-a-step-x-times-in-spring-batch and https://stackoverflow.com/questions/40975705/how-to-run-a-step-in-a-loop-in-spring-batch-updated – Mahmoud Ben Hassine Sep 05 '22 at 09:40

0 Answers0