title: Java ExecutorService - why does this program keep running?
body: <p>I'm trying to build something like a background task executor which terminates background tasks after a certain time if there's no answer (background tasks call webservices and they can time-out but I need to make sure they time out under a certain time)</p>
  
  <p>So I have this as an experiment but if I run this the program does not terminate. I wonder if its because a background thread is still active maybe? How can I shut this down?</p>
  
  <pre><code>public class Test {
  
  public static class Task implements Callable&lt;Object&gt; {
  
      @Override
      public Object call() throws Exception {
          while(true) {}
      }
  
  }
  
  public static void main(String[] args) {
      try {
          Task t = new Task();
          ExecutorService executor = Executors.newSingleThreadExecutor();
          executor.invokeAll(Arrays.asList(t), 5L, TimeUnit.SECONDS);
          executor.shutdown();
          System.out.println("DONE");
      } 
      catch (InterruptedException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>