title: java.util.concurrent.RejectedExecutionException: rejected from java.util.concurrent.ThreadPoolExecutor
body: <p>I have an integrated executor service to execute the tasks concurrently and when used without <code>Future</code>, everything is working fine. In order to check tasks completion and no failure from the executor threads, I have added an <code>Future</code> and trying to check failure state.</p>
  <p>Sample Code:</p>
  <pre class="lang-scala prettyprint-override"><code>val pool = Executors.newFixedThreadPool(THREAD_COUNT)
  implicit val context = ExecutionContext.fromExecutorService(pool)
  
  var index = 0
  while (index &lt; employeeJobDataList.size()) {
      val startIndex = index
      var endIndex = index + BATCH_THRESHOLD
  
      if (startIndex + BATCH_THRESHOLD &gt;= employeeJobDataList.size()) {
          endIndex = employeeJobDataList.size()
      }
  
      val future = Future({
          upsertsFailedBatches.addAll(batchSaveInDDB(employeeJobDataList.subList(startIndex, endIndex), failedList))
      })
      future.onFailure { case e : Throwable =&gt; errorFromExecutorService . append (e.toString) }
      index = index + BATCH_THRESHOLD
  }
  
  context.shutdown()
  while (!context.isTerminated()) {
      Thread.sleep(THREAD_SLEEP_TIME_MILLI)
  }
  </code></pre>
  <p>Error details:</p>
  <pre><code>java.util.concurrent.RejectedExecutionException: Task scala.concurrent.impl.CallbackRunnable@74a938eb rejected from java.util.concurrent.ThreadPoolExecutor@5e5fcd94[Shutting down, pool size = 10, active threads = 10, queued tasks = 87323, completed tasks = 213]
      at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
      at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
      at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
      at scala.concurrent.impl.ExecutionContextImpl$$anon$1.execute(ExecutionContextImpl.scala:136)
      at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:44)
      at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:252)
      at scala.concurrent.Promise$class.complete(Promise.scala:55)
      at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:157)
      at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>