1

I need to schedule a spring batch job from controller with dynamic cron value. In application there is a page where User can change the details of the job like start time, end time and the days it can be run. So once user changes any details and saves, it comes to controller. From controller I need to create the cron expression and schedule the job. If User changes again, the job needs to be rescheduled. Anyone let me know how to do it.

Mohan
  • 21
  • 1
  • Does this answer your question? [How to schedule a cron job in spring boot without using @Scheduled() annotation](https://stackoverflow.com/questions/56938152/how-to-schedule-a-cron-job-in-spring-boot-without-using-scheduled-annotation) – Mahmoud Ben Hassine Jul 16 '20 at 09:41
  • If you really need to use annotations, you can use a SpEL expression in the annotation that refers to another bean that provides the value, and refresh the application context each time the user changes the config. But that's not straightforward, I think a programmatic approach (see duplicate question) is better for your use case. – Mahmoud Ben Hassine Jul 16 '20 at 09:47
  • No. The example is task rather than a spring batch job. – Mohan Jul 16 '20 at 10:41
  • Well the task's code could be `jobLauncher.run(myJob, myParams)` and you can schedule your spring batch jobs dynamically as shown in the example. – Mahmoud Ben Hassine Jul 16 '20 at 11:13

0 Answers0