title: Java ScheduledFuture doesn't wait for task to finish
body: <p>I have problem. I am using the following code:</p>
  <pre><code>ScheduledExecutorService tradingPool = Executors.newScheduledThreadPool(1);
  Runnable runTradingTask = () -&gt; {
      new TradingDriver().run();
  };
  ScheduledFuture&lt;?&gt; scheduledTradingFuture = tradingPool.scheduleAtFixedRate(runTradingTask, 0, 1, TimeUnit.SECONDS);
  </code></pre>
  <p>In my <code>TradingDriver.run()</code> I have a few SQL statements, so that takes some time, arround 1.5 seconds, but I noticed that the next run already started. To check if my thoughts were right I printed &quot;Started&quot; and &quot;Ended&quot; at the endpoints of the function. And this was my result:</p>
  <pre><code>Started
  Started
  Ended
  Started
  Ended
  Started
  Ended
  Started
  </code></pre>
  <p>As you can see it prints 2x &quot;Started&quot;, so that means another run gets started while the first one didn't finish.
  Now I have seen this post: <a href="https://stackoverflow.com/questions/20197654/scheduledexecutorservice-wait-for-task-to-complete">ScheduledExecutorService wait for task to complete</a>, but I can see that the ScheduledFuture doesn't wait for finish.</p>
  <p>How can I run the <code>TradingDriver.run()</code> continuously with 1 second between executions?</p>