Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Concurrency : ExecutorService : invokeAll Method  RSS feed

 
T. Sandeep Jaggi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was testing “<T> List<Future<T>> invokeAll(Collection<? Extends Callable<T>> tasks, long timeout, and TimeUnit unit)” method in ExecutorService and I was shocked with its behavior, I tested on java 7.0.

I found that if any of task fails to finish due to timeout being breached and if I call get() method on any of future (irrespective of whether the callable associated with it finished successfully or was cancelled because “timeout” time had elapsed) I am getting java.util.concurrent.CancellationException. Not sure if I am doing something wrong?
Or is it expected behaviour? Should the exception be not only thrown for tasks which were cancelled? Also not sure if it is logical to throw a runtime exception (CancellationException) when developer can/wants to recover from this issue, I mean he wants that within defined time (timeout) if everything finishes then it is fine else he might have some other strategy.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CancellationException comes when job is cancelled. Show us some code you tried so that we can help..
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!