Java Spring Extender @Scheduled to read a file


I have tasks to do as soon as I upload my application, they are executed repeatedly like this:

  @Scheduled(fixedRate = 10000)  
  public void scheduleFixedRateTask() {
        System.out.println("Fixed rate task - " + System.currentTimeMillis()/10000);

However sometimes I need to update the time interval and I didn't want to have to stop the application every time to do that. So I was wondering if there is a way to extend @Scheduled from spring so that it reads some configuration file, how?


You can parameterize Spring's annotation, the parameter is a little different:

//fixedDelay task:
@Scheduled(fixedDelayString = "${}")

//fixedRate task:
@Scheduled(fixedRateString = "${}")

//A cron expression based task:
@Scheduled(cron = "${cron.expression}")

Then just add the property to your configuration file.


Scroll to Top