|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ExecutorCompletionService | Line # 81 | 29 | 16 | 79.6% |
0.7962963
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ExecutorCompletionService.QueueingFuture | Line # 89 | 3 | 2 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (40) | |||
| Result | |||
|
0.44067797
|
ScheduledExecutorTest.testInvokeAny4
ScheduledExecutorTest.testInvokeAny4
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testInvokeAny3
ScheduledExecutorTest.testInvokeAny3
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testInvokeAny3
ThreadPoolExecutorTest.testInvokeAny3
|
1 PASS | |
|
0.44067797
|
ExecutorCompletionServiceTest.testNewTaskForRunnable
ExecutorCompletionServiceTest.testNewTaskForRunnable
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testInvokeAny4
ThreadPoolExecutorTest.testInvokeAny4
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testInvokeAny4
ThreadPoolExecutorTest.testInvokeAny4
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testTimedInvokeAny4
ThreadPoolExecutorTest.testTimedInvokeAny4
|
1 PASS | |
|
0.44067797
|
ExecutorCompletionServiceTest.testNewTaskForCallable
ExecutorCompletionServiceTest.testNewTaskForCallable
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testTimedInvokeAny4
ThreadPoolExecutorTest.testTimedInvokeAny4
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testTimedInvokeAny3
ScheduledExecutorTest.testTimedInvokeAny3
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testInvokeAny3
ScheduledExecutorTest.testInvokeAny3
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testTimedInvokeAny3
ScheduledExecutorTest.testTimedInvokeAny3
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testTimedInvokeAny4
ScheduledExecutorTest.testTimedInvokeAny4
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testTimedInvokeAny4
ScheduledExecutorTest.testTimedInvokeAny4
|
1 PASS | |
|
0.44067797
|
ExecutorCompletionServiceTest.testPoll2
ExecutorCompletionServiceTest.testPoll2
|
1 PASS | |
|
0.44067797
|
ScheduledExecutorTest.testInvokeAny4
ScheduledExecutorTest.testInvokeAny4
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testTimedInvokeAny3
ThreadPoolExecutorTest.testTimedInvokeAny3
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testTimedInvokeAny3
ThreadPoolExecutorTest.testTimedInvokeAny3
|
1 PASS | |
|
0.44067797
|
ThreadPoolExecutorTest.testInvokeAny3
ThreadPoolExecutorTest.testInvokeAny3
|
1 PASS | |
|
0.40677965
|
ThreadPoolExecutorTest.testTimedInvokeAny5
ThreadPoolExecutorTest.testTimedInvokeAny5
|
1 PASS | |
|
0.40677965
|
AbstractExecutorServiceTest.testTimedInvokeAny4
AbstractExecutorServiceTest.testTimedInvokeAny4
|
1 PASS | |
|
0.40677965
|
AbstractExecutorServiceTest.testInvokeAny3
AbstractExecutorServiceTest.testInvokeAny3
|
1 PASS | |
|
0.40677965
|
AbstractExecutorServiceTest.testInvokeAny4
AbstractExecutorServiceTest.testInvokeAny4
|
1 PASS | |
|
0.40677965
|
ScheduledExecutorTest.testTimedInvokeAny5
ScheduledExecutorTest.testTimedInvokeAny5
|
1 PASS | |
|
0.40677965
|
AbstractExecutorServiceTest.testTimedInvokeAny5
AbstractExecutorServiceTest.testTimedInvokeAny5
|
1 PASS | |
|
0.40677965
|
ScheduledExecutorTest.testTimedInvokeAny5
ScheduledExecutorTest.testTimedInvokeAny5
|
1 PASS | |
|
0.40677965
|
AbstractExecutorServiceTest.testInvokeAny5
AbstractExecutorServiceTest.testInvokeAny5
|
1 PASS | |
|
0.40677965
|
ExecutorCompletionServiceTest.testTake2
ExecutorCompletionServiceTest.testTake2
|
1 PASS | |
|
0.40677965
|
ThreadPoolExecutorTest.testTimedInvokeAny5
ThreadPoolExecutorTest.testTimedInvokeAny5
|
1 PASS | |
|
0.40677965
|
ThreadPoolExecutorTest.testInvokeAny5
ThreadPoolExecutorTest.testInvokeAny5
|
1 PASS | |
|
0.40677965
|
ExecutorCompletionServiceTest.testTake
ExecutorCompletionServiceTest.testTake
|
1 PASS | |
|
0.40677965
|
ScheduledExecutorTest.testInvokeAny5
ScheduledExecutorTest.testInvokeAny5
|
1 PASS | |
|
0.40677965
|
ExecutorCompletionServiceTest.testPoll1
ExecutorCompletionServiceTest.testPoll1
|
1 PASS | |
|
0.40677965
|
ThreadPoolExecutorTest.testInvokeAny5
ThreadPoolExecutorTest.testInvokeAny5
|
1 PASS | |
|
0.40677965
|
AbstractExecutorServiceTest.testTimedInvokeAny3
AbstractExecutorServiceTest.testTimedInvokeAny3
|
1 PASS | |
|
0.40677965
|
ScheduledExecutorTest.testInvokeAny5
ScheduledExecutorTest.testInvokeAny5
|
1 PASS | |
|
0.18644068
|
ExecutorCompletionServiceTest.testSubmitNPE
ExecutorCompletionServiceTest.testSubmitNPE
|
1 PASS | |
|
0.18644068
|
ExecutorCompletionServiceTest.testSubmitNPE2
ExecutorCompletionServiceTest.testSubmitNPE2
|
1 PASS | |
|
0.06779661
|
ExecutorCompletionServiceTest.testConstructorNPE
ExecutorCompletionServiceTest.testConstructorNPE
|
1 PASS | |
|
0.06779661
|
ExecutorCompletionServiceTest.testConstructorNPE2
ExecutorCompletionServiceTest.testConstructorNPE2
|
1 PASS | |
| 1 | /* | |
| 2 | * Written by Doug Lea with assistance from members of JCP JSR-166 | |
| 3 | * Expert Group and released to the public domain, as explained at | |
| 4 | * http://creativecommons.org/licenses/publicdomain | |
| 5 | */ | |
| 6 | ||
| 7 | package edu.emory.mathcs.backport.java.util.concurrent; | |
| 8 | import edu.emory.mathcs.backport.java.util.concurrent.*; // for javadoc (till 6280605 is fixed) | |
| 9 | ||
| 10 | /** | |
| 11 | * A {@link CompletionService} that uses a supplied {@link Executor} | |
| 12 | * to execute tasks. This class arranges that submitted tasks are, | |
| 13 | * upon completion, placed on a queue accessible using <tt>take</tt>. | |
| 14 | * The class is lightweight enough to be suitable for transient use | |
| 15 | * when processing groups of tasks. | |
| 16 | * | |
| 17 | * <p> | |
| 18 | * | |
| 19 | * <b>Usage Examples.</b> | |
| 20 | * | |
| 21 | * Suppose you have a set of solvers for a certain problem, each | |
| 22 | * returning a value of some type <tt>Result</tt>, and would like to | |
| 23 | * run them concurrently, processing the results of each of them that | |
| 24 | * return a non-null value, in some method <tt>use(Result r)</tt>. You | |
| 25 | * could write this as: | |
| 26 | * | |
| 27 | * <pre> | |
| 28 | * void solve(Executor e, | |
| 29 | * Collection<Callable<Result>> solvers) | |
| 30 | * throws InterruptedException, ExecutionException { | |
| 31 | * CompletionService<Result> ecs | |
| 32 | * = new ExecutorCompletionService<Result>(e); | |
| 33 | * for (Callable<Result> s : solvers) | |
| 34 | * ecs.submit(s); | |
| 35 | * int n = solvers.size(); | |
| 36 | * for (int i = 0; i < n; ++i) { | |
| 37 | * Result r = ecs.take().get(); | |
| 38 | * if (r != null) | |
| 39 | * use(r); | |
| 40 | * } | |
| 41 | * } | |
| 42 | * </pre> | |
| 43 | * | |
| 44 | * Suppose instead that you would like to use the first non-null result | |
| 45 | * of the set of tasks, ignoring any that encounter exceptions, | |
| 46 | * and cancelling all other tasks when the first one is ready: | |
| 47 | * | |
| 48 | * <pre> | |
| 49 | * void solve(Executor e, | |
| 50 | * Collection<Callable<Result>> solvers) | |
| 51 | * throws InterruptedException { | |
| 52 | * CompletionService<Result> ecs | |
| 53 | * = new ExecutorCompletionService<Result>(e); | |
| 54 | * int n = solvers.size(); | |
| 55 | * List<Future<Result>> futures | |
| 56 | * = new ArrayList<Future<Result>>(n); | |
| 57 | * Result result = null; | |
| 58 | * try { | |
| 59 | * for (Callable<Result> s : solvers) | |
| 60 | * futures.add(ecs.submit(s)); | |
| 61 | * for (int i = 0; i < n; ++i) { | |
| 62 | * try { | |
| 63 | * Result r = ecs.take().get(); | |
| 64 | * if (r != null) { | |
| 65 | * result = r; | |
| 66 | * break; | |
| 67 | * } | |
| 68 | * } catch (ExecutionException ignore) {} | |
| 69 | * } | |
| 70 | * } | |
| 71 | * finally { | |
| 72 | * for (Future<Result> f : futures) | |
| 73 | * f.cancel(true); | |
| 74 | * } | |
| 75 | * | |
| 76 | * if (result != null) | |
| 77 | * use(result); | |
| 78 | * } | |
| 79 | * </pre> | |
| 80 | */ | |
| 81 | public class ExecutorCompletionService implements CompletionService { | |
| 82 | private final Executor executor; | |
| 83 | private final AbstractExecutorService aes; | |
| 84 | private final BlockingQueue completionQueue; | |
| 85 | ||
| 86< | ||