From c7999a908d88fe958dafd3804dc7afd4f1b0f639 Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Wed, 7 May 2025 21:30:01 +0200 Subject: [PATCH] add assignment --- u07-2/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 u07-2/README.md diff --git a/u07-2/README.md b/u07-2/README.md new file mode 100644 index 0000000..506d20d --- /dev/null +++ b/u07-2/README.md @@ -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 { + public SimpleExecutorCompletionService(ExecutorService ex) { … } + + // Submit task to ex for execution: + public Future submit(Callable task) { … } + + // Fetch result of some finished task if available (else null): + public Future 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). \ No newline at end of file