title: Why does the program wait for the schedule() to finish but doesn't wait for the scheduleWithFixedDelay()?
body: <p>Here's the code:</p>
  
  <pre><code>ScheduledExecutorService service = null;
  try {
      service = Executors.newSingleThreadScheduledExecutor();
      Runnable task1 = () -&gt; System.out.println("Executed only once");
      Runnable task2 = () -&gt; System.out.println("Executed repeatedly");
  
      service.schedule(task1, 5, TimeUnit.SECONDS);
      service.scheduleWithFixedDelay(task2, 6, 2, TimeUnit.SECONDS);
  } finally {
      if (service != null) {
          service.shutdown();
      }
  }
  </code></pre>
  
  <p>When executing the above code the program waits 5 seconds to run schedule() but after that it finishes without running the scheduleWithFixedDelay().</p>
  
  <p>I suspect the reason is that schedule() is executed synchronously unlike the scheduleWithFixedDelay() but I haven't found the arguments in favor of this in the docs.</p>