title: Start performing an action every minute after getting to a web page
body: <p>I am developing a Java web application using Spring.</p>
  <p>What I would like to do is that after the user gets to a page, the code starts running a function every 10 seconds, keeping track on the time the last action was performed.</p>
  <p>I tried to do so with a Scheduler but it starts running immediately - and not only after the user gets to a page.</p>
  <pre><code>@Scheduled(fixedRate = 60000)
  public void run(String param) {
      //just an example of action to be performed repeatedly
      System.out.println(&quot;Previously performed action was &quot; + new SimpleDateFormat(&quot;dd/MM/yyyy HH:mm:ss&quot;).format(previousActionTime)) + &quot; with &quot; + param);
      //update previousActionTime
      previousActionTime.setSeconds(previousActionTime.getSeconds() + 10);
  }
  </code></pre>
  <p>Moreover I don't know what it is a convenient way to store the time when the last action automated action was performed.</p>
  <p>The scheduler should be somehow activated when browsing to the page:</p>
  <pre><code>@RequestMapping(value = &quot;/hellopage&quot;, method = { RequestMethod.POST, RequestMethod.GET })
  public String hellopage(HttpServletRequest request, HttpServletResponse response) {
          // Activate scheduler
          run(request.getParameter(&quot;param1&quot;))
          ...
  }
  </code></pre>
  <p>The scheduler (or whatever performs the automated actions) should stop as soon as the user gets again to the same web page triggering the automated actions and should run in background not blocking any other code from execution (to be precise, I cannot simply put a while loop with Sys.sleep in the function mapped to the page URL request why the page should do other things)</p>
  <p>Any help?</p>