title: Is it possible to interrupt a specific thread of an ExecutorService?
body: <p>If I have an <code>ExecutorService</code> to which I feed Runnable tasks, can I select one and interrupt it?<br/>
  I know I can cancel the Future returned (also mentioned <a href="https://stackoverflow.com/questions/9280846/how-to-interrupt-executors-thread">Here: how-to-interrupt-executors-thread</a>), but how can I raise an <code>InterruptedException</code>. Cancel doesn't seem to do it (event though it should by looking at the sources, maybe the OSX implementation differs). At least this snippet doesn't print 'it!' Maybe I'm misunderstaning something and it's not the custom runnable that gets the exception?</p>
  
  <pre><code>public class ITTest {
  static class Sth {
      public void useless() throws InterruptedException {
              Thread.sleep(3000);
      }
  }
  
  static class Runner implements Runnable {
      Sth f;
      public Runner(Sth f) {
          super();
          this.f = f;
      }
      @Override
      public void run() {
          try {
              f.useless();
          } catch (InterruptedException e) {
              System.out.println("it!");
          }
      }
  }
  public static void main(String[] args) throws InterruptedException, ExecutionException {
      ExecutorService es = Executors.newCachedThreadPool();
      Sth f = new Sth();
      Future&lt;?&gt; lo = es.submit(new Runner(f));
      lo.cancel(true); 
      es.shutdown();
  }
  </code></pre>
  
  <p>}</p>