add assignment b
This commit is contained in:
parent
c7999a908d
commit
9ec2dae73f
|
@ -12,13 +12,22 @@ public class SimpleExecutorCompletionService<ResultType> {
|
||||||
// Fetch result of some finished task if available (else null):
|
// Fetch result of some finished task if available (else null):
|
||||||
public Future<ResultType> poll() { … }
|
public Future<ResultType> poll() { … }
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Use class `SimpleExecutorCompletionServiceTester` oin the file server to test your class. If your
|
Use class `SimpleExecutorCompletionServiceTester` oin the file server to test your class. If your
|
||||||
implementation is correct, the numbers printed with "… received result" should appear in mostly[^1]
|
implementation is correct, the numbers printed with "… received result" should appear in mostly[^1]
|
||||||
ascending order. Method `Future.isDone()` could be helpful for your implementation.
|
ascending order. Method `Future.isDone()` could be helpful for your implementation.
|
||||||
|
|
||||||
|
b) Add the following method to your class:
|
||||||
|
```java
|
||||||
|
// Fetch result of some finished task (blocks until some has finished):
|
||||||
|
public Future<ResultType> take() throws InterruptedExecution { … }
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that you have to change the submit method from (a), too, so that when a task finishes, the
|
||||||
|
threads waiting in take for a task to finish are notified. Use class
|
||||||
|
`SimpleExecutorCompletionServiceTester_with_take` on the server to test your class.
|
||||||
|
|
||||||
[^1]: This order is not really guaranteed: While the "internal" length of each task would indeed produce this order,
|
[^1]: This order is not really guaranteed: While the "internal" length of each task would indeed produce this order,
|
||||||
the total execution time of a task may be longer due to external delays by the thread pool (e.g. how long it takes
|
the total execution time of a task may be longer due to external delays by the thread pool (e.g. how long it takes
|
||||||
to start a submitted task) and by other threads (e.g. preemption).
|
to start a submitted task) and by other threads (e.g. preemption).
|
Loading…
Reference in New Issue