title: Configuring multiple tasks with Spring scheduler having configurable triggers
body: <p>I need some help with some design as well as spring scheduler related code. I am trying to write few utility classes, where by all the tasks (which are going to do some async processing) are scheduled at regular intervals.</p>
  
  <p>So, I create a <code>Task</code> class which has a <code>execute()</code> method, which needs to be implemented by each task.</p>
  
  <pre><code>public interface Task
  {
      void execute();
  }
  
  public class TaskOne implements Task
  {
      @Override
      public void execute()
      {
          // do something
      }
  }
  
  public class TaskTwo implements Task
  {
      @Override
      public void execute()
      {
          // do something
      }
  }
  
  @Component
  public class ScheduledTasks
  {
      @Scheduled(fixedRate = 5000)
      public void runTask()
      {
          Task taskOne = new TaskOne();
          taskOne.execute();
          Task taskTwo = new TaskTwo();
          taskTwo.execute();
      }
  }
  </code></pre>
  
  <p>I need to run different tasks at different interval, which I want to be configurable without the need of restarting the server. By this, I mean that time specified here can be changed without a restart. 
  <code>@Scheduled(fixedRate = configurable, with some initial value)</code></p>
  
  <p>Normally, what is the best way of doing this ? </p>
  
  <p>One approach I can think of is:</p>
  
  <pre><code>1. Keep the trigger (periodic or cron) for each task in db
  2. Load these triggers at the time of start up
  3. Somehow, annotate the execute() methods with the proper value. This is going to be technically stiff.
  4. If we want to change the job interval timing, update the db and refresh the caches.
  </code></pre>
  
  <p>Also, if some one can share some code snippet or suggest something like a small library, that would be highly appreciated. Thanks.</p>