Som Snytt
unread,Jan 31, 2013, 3:08:19 AM1/31/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-internals
ExecutionService.shutdown allows previously submitted tasks to complete.
However, I suppose that if I shutdown an ExecutionContext, the onCompletes of previously submitted futures won't get run. Ought they?
Maybe there could be a policy setting to decide what to do with them.
(One option would be to run on the current thread if the target executor.isShutdown. Or perhaps only if the target is the current executor.)
(Alternatively, the EC could have a shutdown state that gets propagated to the underlying ES only after callbacks have run. Just thinking aloud.)
My use case is that tasks on A create tasks on B, so once all futures are created, it's convenient to A.shutdown without any book-keeping.
Footnote, error from simple test is clear:
Exception in thread "pool-1-thread-1" java.util.concurrent.RejectedExecutionException: Task scala.concurrent.impl.CallbackRunnable@f1bb79c rejected from java.util.concurrent.ThreadPoolExecutor@64b36a83[Shutting down, pool size = 2, active threads = 2, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2013)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:816)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1337)
at scala.concurrent.impl.ExecutionContextImpl$$anon$1.execute(ExecutionContextImpl.scala:118)
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.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
This other error is more obscure:
java.lang.IllegalStateException: Promise already completed.
at scala.concurrent.Promise$class.complete(Promise.scala:55)
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:58)
at scala.concurrent.Promise$class.failure(Promise.scala:107)
at scala.concurrent.impl.Promise$DefaultPromise.failure(Promise.scala:58)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:257)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)