title: What is the difference between ExecutorService.submit and ExecutorService.execute in this code in Java?
body: <p>I am learning to use <code>ExectorService</code> to pool <code>threads</code> and send out tasks. I have a simple program below</p>
  
  <pre><code>import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  import java.util.concurrent.TimeUnit;
  
  
  class Processor implements Runnable {
  
      private int id;
  
      public Processor(int id) {
          this.id = id;
      }
  
      public void run() {
          System.out.println("Starting: " + id);
  
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e) {
              System.out.println("sorry, being interupted, good bye!");
              System.out.println("Interrupted " + Thread.currentThread().getName());
              e.printStackTrace();
          }
  
          System.out.println("Completed: " + id);
      }
  }
  
  
  public class ExecutorExample {
  
      public static void main(String[] args) {
          Boolean isCompleted = false;
  
          ExecutorService executor = Executors.newFixedThreadPool(2);
  
          for (int i = 0; i &lt; 5; i++) {
              executor.execute(new Processor(i));
          }
  
          //executor does not accept any more tasks but the submitted tasks continue
          executor.shutdown();
  
          System.out.println("All tasks submitted.");
  
          try {
              //wait for the exectutor to terminate normally, which will return true
              //if timeout happens, returns false, but this does NOT interrupt the threads
              isCompleted = executor.awaitTermination(100, TimeUnit.SECONDS);
              //this will interrupt thread it manages. catch the interrupted exception in the threads
              //If not, threads will run forever and executor will never be able to shutdown.
              executor.shutdownNow();
          } catch (InterruptedException e) {
          }
  
          if (isCompleted) {
              System.out.println("All tasks completed.");
          } else {
              System.out.println("Timeout " + Thread.currentThread().getName());
          }
      }
  }
  </code></pre>
  
  <p>It does nothing fancy, but creates two <code>threads</code> and submits 5 tasks in total. After each <code>thread</code> completes its task, it takes the next one,
  In the code above, I use <code>executor.submit</code>. I also changed to <code>executor.execute</code>. But I do not see any difference in the output. In what way are the <code>submit</code> and <code>execute</code> methods different?
  This what the <code>API</code> says</p>
  
  <blockquote>
    <p>Method submit extends base method Executor.execute(java.lang.Runnable) by creating and returning a Future that can be used to cancel execution and/or wait for completion. Methods invokeAny and invokeAll perform the most commonly useful forms of bulk execution, executing a collection of tasks and then waiting for at least one, or all, to complete. (Class ExecutorCompletionService can be used to write customized variants of these methods.)</p>
  </blockquote>
  
  <p>But it's not clear to me as what it exactly means?</p>