2656 |
|
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, |
2657 |
|
long timeout, TimeUnit unit) |
2658 |
|
throws InterruptedException, ExecutionException, TimeoutException { |
2659 |
+ |
int par = mode & SMASK; |
2660 |
|
BulkTask<T>[] fs; BulkTask<T> root; |
2661 |
|
long deadline = unit.toNanos(timeout) + System.nanoTime(); |
2662 |
|
if ((fs = BulkTask.forkAll(tasks, true)) != null && fs.length > 0 && |
2663 |
|
(root = fs[0]) != null) { |
2664 |
|
TimeoutException tex = null; |
2665 |
|
try { |
2666 |
< |
root.get(deadline, TimeUnit.NANOSECONDS); |
2666 |
> |
if (par == 0) // if no workers, caller must execute |
2667 |
> |
root.get(); |
2668 |
> |
else |
2669 |
> |
root.get(deadline, TimeUnit.NANOSECONDS); |
2670 |
|
} catch (TimeoutException tx) { |
2671 |
|
tex = tx; |
2672 |
|
} catch (Throwable ignore) { |