Search code examples
spring-batchschedulingschedule

Use Spring batch for not scheduled process?


I have had experience working with Spring Batch a few months but I have got a doubt a few days ago. I have to process a file and then update a database from it but this is not a scheduled batch process because it has to be executed just once.

  1. Is Spring batch recommended to execute not scheduled processes like this one? Or the fact that is not scheduled has nothing to do with using Spring batch or not

Thanks


Solution

  • Is Spring batch recommended to execute not scheduled processes like this one? Or the fact that is not scheduled has nothing to do with using Spring batch or not

    Yes, the fact that your job has to be executed only once has nothing to do with using Spring Batch or not. There is a difference between developing the job (using Spring Batch or not) and scheduling the job (using cron, quartz, etc).

    For your use case (process a file and then update a database), I would recommend using Spring Batch to develop your job. Then, you can choose to run it:

    • only once or on demand (Spring Batch provides APIs to run the job)
    • or schedule it to run repeatedly using your favourite scheduler