title: What is the runnable object passed in Java thread pool RejectedExecutionHandler
body: <p>I have <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html#ThreadPoolExecutor%28int,%20int,%20long,%20java.util.concurrent.TimeUnit,%20java.util.concurrent.BlockingQueue,%20java.util.concurrent.ThreadFactory,%20java.util.concurrent.RejectedExecutionHandler%29" rel="noreferrer">thread pool with a RejectedExecutionHandler</a> like this and a Runnable task.</p>
  
  <pre><code>sExecutorService = new ThreadPoolExecutor( ...    new MyRejectionHandler() );
  
  interface MyTask extends Runnable { ... }
  
  class MyTaskImpl implements MyTask { ...}     
  </code></pre>
  
  <p>i execute a task like this</p>
  
  <pre><code>   sExecutorService.submit(myTask);        
  </code></pre>
  
  <p>in rejectedExecution case i was hoping to get hold of rejected Runnable (ie MyTask) and set some field in it marking it as rejected. But i am not able to cast it to MyTask. 
  So what exactly is the  runnable passed t o rejectedExecution ?  It appears not MyTask i submitted . And how can i get hold of the rejected task in RejectedExecutionHandler.</p>
  
  <pre><code>public class MyRejectionHandler implements RejectedExecutionHandler{  
     public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor)  {
      MyTask myTask = (MyTask) runnable; // exception
      myTask.doSomething();
     }
  java.lang.ClassCastException: java.util.concurrent.FutureTask cannot be cast to MyTask       
  </code></pre>