title: Future Task rejected from ThreadPoolExecutor
body: <p>I have a <code>ThreadPoolExecutor</code> and I submit a task to it.</p>
  
  <pre><code>private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue&lt;Runnable&gt;(1));
  </code></pre>
  
  <p>This code submits the <code>Runnable</code> to the <code>ThreadPoolExecutor</code>.</p>
  
  <pre><code> protected void waitAndSweep(final String symbol) {
  
      runnable = new Runnable() {
        public void run() { /* irrelevant code */ }
      };
  
      try {
        Future&lt;?&gt; self = threadPoolExecutor.submit(runnable);
        futures.add(self);
      } catch (RejectedExecutionException re) {
        /* this exception will be thrown when wait and sweep is called more than twice.
         * threadPoolExecutor can have one running task and one waiting task.
         */
      } catch (Exception e) {
        logEvent(StrategyEntry.ERROR, "waitAndSweep", symbol, "Exception caught...", e);
      }
    }
  </code></pre>
  
  <p>The following code stops the task.</p>
  
  <pre><code>protected synchronized void stop(StrategyEntry entry) throws Exception {
      for (Object future : futures) {
        ((Future&lt;?&gt;) future).cancel(true);
      }
      futures.clear();
  
      threadPoolExecutor.shutdown();
  }
  </code></pre>
  
  <p>The problem here is: When I try to stop the task, I am getting following exception:</p>
  
  <blockquote>
    <p>Task java.util.concurrent.FutureTask@3a475611 rejected from java.util.concurrent.ThreadPoolExecutor@216393fb[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]</p>
  </blockquote>