Logo Mustafa Bayar
  • Home
  • About
  • Experiences
  • Education
  • Posts
  • Dark Theme
    Light Theme Dark Theme System Theme
Logo Inverted Logo
  • Tags
  • ESIM
  • HowTo
  • Java
  • Spring
Hero Image
Dynamic Task Scheduling with Spring

Summary Spring makes it very easy to schedule a job to run periodically. All we need to do is to put @Scheduled annotation above the method and provide the necessary parameters such as fixedRate or cron expression. But when it comes to change this fixedRate on the fly, @Scheduled annotation is not enough. Ultimately, what I wanted to do was periodically load my configuration table from a database. But the fixedRate which indicates how frequently I will load this table is also stored in the very same database. So what I wanted to do was reading this value from a database and schedule the task according to it. Whenever the value changes, the next execution time should change with it too. Before going into next step, I also created a repository for all the code in this tutorial to show how this scheduling works. You can find the example code in my Github page Also at the end I will add an alternative way for scheduling with exact date and a way to start the scheduler from external service (like controller). Please check the above repository for various scheduling examples.

  • Java
  • Spring
Saturday, September 8, 2018 | 8 minutes Read

Toha Theme Logo Toha
© 2024 Copyright.
Powered by Hugo Logo