add assignment

This commit is contained in:
Luca Conte 2025-05-07 21:30:01 +02:00
parent 7a53d60ef4
commit c7999a908d
1 changed files with 24 additions and 0 deletions

24
u07-2/README.md Normal file
View File

@ -0,0 +1,24 @@
# Problem 7.2: Implementation of `ExecutorCompletionService`
a) Implement the following simplified version of class `java.util.concurrent.ExecutorCompletionService`:
```java
public class SimpleExecutorCompletionService<ResultType> {
public SimpleExecutorCompletionService(ExecutorService ex) { … }
// Submit task to ex for execution:
public Future<ResultType> submit(Callable<ResultType> task) { … }
// Fetch result of some finished task if available (else null):
public Future<ResultType> poll() { … }
}
```
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]
ascending order. Method `Future.isDone()` could be helpful for your implementation.
[^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
to start a submitted task) and by other threads (e.g. preemption).