spring-bootspring-batchspring-scheduledspring-batch-tasklet

How to assess whether to use spring batch or scheduler in application?


I have a business logic already developed in spring boot that needs to be run once in every 60 days. I'm little confused on whether convert it to spring batch or use scheduler annotation. What all factors should I consider to assess the same? Does either of them has any performance upper-hand over the other? I'm new to the scheduler-batch concept and this is my first time work on the same.


Solution

  • How to assess whether to use spring batch or scheduler in application?

    Spring Batch is not a scheduler, so it's not an either or question. You can use both, for example use a scheduler to schedule a Spring Batch job to run at a given time.

    The question you should be asking is: is it worth transforming the business logic you already developed in spring boot in a Spring Batch job to benefit from what Spring Batch offers (the whole app could remain a boot app).

    As a side note, since your job needs to be run every 60 days, using @Scheduled means you would have a JVM running for two months to run a job. Unless you are planning to use the same JVM for other things in the meantime, this would be an inefficient use of resources. Other scheduling mechanisms like cron is more appropriate in this case.