title: Spring : @Scheduled task triggered through the @Controller and Websocket
body: <p>I have an <code>@Scheduled</code> task which send data to a client every sec throught a websocket.</p>
  
  <p>My need is to start running my scheduled task only when the client ask for it.</p>
  
  <p>Instead of, my task starts when my server starts. it's not the behavior i want.</p>
  
  <p>currently, I have a bean of my scheduled task which is declared in my SchedulingConfigurer :</p>
  
  <pre><code>@Configuration
  @EnableScheduling
  public class SchedulingConfigurer implements org.springframework.scheduling.annotation.SchedulingConfigurer {
  
      @Bean
      public ThreadPoolTaskScheduler taskScheduler() {
          return new ThreadPoolTaskScheduler();
      }
  
      @Bean
      public ScheduledTask scheduledTask() {
          return new ScheduledTask();
      }
  
      @Override
      public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
          taskRegistrar.setTaskScheduler(taskScheduler());
      }
  
  }
  </code></pre>
  
  <p>Here is my spring controller code :</p>
  
  <pre><code>@MessageMapping("/hello")
  public void greeting() throws Exception {
     //How do I start my scheduled task here ?
  }
  </code></pre>
  
  <p>Maybe isn't possible to do that with <code>@Scheduled</code> annotation and i have to use the <code>TaskScheduler</code> interface ?</p>