4

executor をシャットダウンするとき、どこで RejectedExecutionExceptions をキャッチする必要がありますか? 私は試した:

 future {
        Option(reader.readLine)
      } onComplete {
        case Success(v) =>
        case Failure(e) => e match {
          case ree: RejectedExecutionException =>
          // doesn't work
      }

と :

 try {
        future {
          Option(reader.readLine)
        } onComplete {
          ...
        }
      } catch {
        case ree: RejectedExecutionException =>
          // doesn't work
      }

も機能しません。まだ取得中:

Exception in thread "pool-99-thread-1" java.util.concurrent.RejectedExecutionException
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1768)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)
at scala.concurrent.impl.ExecutionContextImpl.execute(ExecutionContextImpl.scala:105)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:37)
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:133)
at scala.concurrent.Promise$class.complete(Promise.scala:55)
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:58)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
4

2 に答える 2

5

これは RejectedExecutionHandler によって処理される必要があります。またはカスタムjava.util.concurrent.ThreadPoolExecutor.DiscardPolicy実装による。

このエグゼキュータは、RejectedExecutionException を暗黙のうちに渡します。

val executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue[Runnable], Executors.defaultThreadFactory, new DiscardPolicy)
于 2013-07-22T08:18:35.117 に答える