title: Thread.sleep within @Scheduled method in Spring
body: <p>I have a method that is scheduled to run each X ms.</p>
  
  <p>This method is launching a new method within a new thread.</p>
  
  <p>Nevertheless, I want to delay this method before counting again.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>@Scheduled(fixedRate = RATE_IN_MS)
  public void myMethod(){
      new Thread(() -&gt; method()).start();
      Thread.sleep(RATE_IN_MS);
  }
  </code></pre>
  
  <p>The problem is that the behavior is not like I want.</p>
  
  <p>Here is the current behavior:</p>
  
  <ol>
  <li>After RATE_IN_MS myMethod is launched.</li>
  <li>method() start running in a different thread.</li>
  <li>After RATE_IN_MS myMethod is launched.</li>
  </ol>
  
  <p>The problem: Why does my sleep method didn't delay the next launch of myMethod? RATE_IN_MS (by fixedDelay) + RATE_IN_MS (because of Thread.sleep(RATE_IN_MS) need to be the real delay between them.</p>
  
  <p>What I'm missing here?</p>
  
  <p>Thanks!</p>