title: stop Callable task in ExecutorService
body: <p>I'm learning concurrency and made some naive program to play with <code>ExecutorService</code> and <code>Future</code> tasks.</p>
  
  <p>Also I want to check why <code>instanceof</code> is bad in some cases.</p>
  
  <pre><code>public class Test {
  
  static enum Some {
      FOO;
  }
  
  static abstract class Foo {
      public abstract Some getType();
  }
  
  static class FooExt extends Foo {
      public Some getType() {
          return Some.FOO;
      }
  }
  
  public static void main(String[] args) {
  
      ExecutorService service = Executors.newFixedThreadPool(2);
      final CountDownLatch start = new CountDownLatch(1);
      Future&lt;Integer&gt; f1 = service.submit(new Callable&lt;Integer&gt;() {
          @Override
          public Integer call() {
              try {
                  start.await();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              System.out.println("Task started...");
              int a = 0;
              Foo foo = new FooExt();
              while (!Thread.currentThread().isInterrupted()) {
                  if (foo instanceof FooExt) {
                      a++;
                  }
              }
              System.out.println("Task ended...");
              return a;
          }
      });
  
      Future&lt;Integer&gt; f2 = service.submit(new Callable&lt;Integer&gt;() {
          @Override
          public Integer call() {
              try {
                  start.await();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              System.out.println("Task started...");
              int a = 0;
              Foo foo = new FooExt();
              while (!Thread.currentThread().isInterrupted()) {
                  if (foo.getType() == Some.FOO) {
                      a++;
                  }
              }
              System.out.println("Task ended...");
              return a;
          }
      });
      start.countDown();
      try {
          Thread.sleep(100);
      } catch (InterruptedException e) {
      }
      service.shutdownNow();
      System.out.println("service is shutdowned...");
      try {
          System.out.println("instanceof: "+f1.get());
          System.out.println("enum: "+f2.get());
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>but unfortunately my code is never terminated, and I cant get any values from my tasks :(</p>