lines = outContent.toString().lines().toList();
- Assertions.assertTrue(lines.stream()
- .allMatch(line -> line.endsWith(String.valueOf(initialValue))));
- }
-}
diff --git a/thread-pool/README.md b/thread-pool/README.md
deleted file mode 100644
index 685b39038..000000000
--- a/thread-pool/README.md
+++ /dev/null
@@ -1,219 +0,0 @@
----
-title: Thread Pool
-category: Concurrency
-language: en
-tag:
- - Asynchronous
- - Performance
- - Resource management
- - Scalability
- - Synchronization
- - Thread management
----
-
-## Also known as
-
-* Worker Pool
-
-## Intent
-
-Efficiently manage a pool of worker threads to execute tasks concurrently, improving resource utilization and performance.
-
-## Explanation
-
-Real-world example
-
-> A real-world analogy for the Thread Pool design pattern can be found in a restaurant kitchen. Imagine a busy restaurant with a limited number of chefs (threads). Instead of hiring a new chef every time an order (task) comes in, the restaurant uses a fixed number of chefs to handle all the incoming orders. Each chef works on one order at a time and then moves on to the next one when finished. This approach ensures that the kitchen operates efficiently without the overhead of hiring and firing chefs continuously, and it prevents the kitchen from becoming overcrowded with too many chefs working at once. This setup allows the restaurant to handle multiple orders concurrently, optimize resource use, and maintain a steady workflow.
-
-In plain words
-
-> Thread Pool is a concurrency pattern where threads are allocated once and reused between tasks.
-
-Wikipedia says
-
-> In computer programming, a thread pool is a software design pattern for achieving concurrency of execution in a computer program. Often also called a replicated workers or worker-crew model, a thread pool maintains multiple threads waiting for tasks to be allocated for concurrent execution by the supervising program. By maintaining a pool of threads, the model increases performance and avoids latency in execution due to frequent creation and destruction of threads for short-lived tasks. The number of available threads is tuned to the computing resources available to the program, such as a parallel task queue after completion of execution.
-
-**Programmatic Example**
-
-Let's first look at our task hierarchy. We have an abstract base class `Task` and concrete tasks `CoffeeMakingTask` and `PotatoPeelingTask`.
-
-```java
-public abstract class Task {
-
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- @Getter
- private final int id;
- @Getter
- private final int timeMs;
-
- public Task(final int timeMs) {
- this.id = ID_GENERATOR.incrementAndGet();
- this.timeMs = timeMs;
- }
-
- @Override
- public String toString() {
- return String.format("id=%d timeMs=%d", id, timeMs);
- }
-}
-
-public class CoffeeMakingTask extends Task {
-
- private static final int TIME_PER_CUP = 100;
-
- public CoffeeMakingTask(int numCups) {
- super(numCups * TIME_PER_CUP);
- }
-
- @Override
- public String toString() {
- return String.format("%s %s", this.getClass().getSimpleName(), super.toString());
- }
-}
-
-public class PotatoPeelingTask extends Task {
-
- private static final int TIME_PER_POTATO = 200;
-
- public PotatoPeelingTask(int numPotatoes) {
- super(numPotatoes * TIME_PER_POTATO);
- }
-
- @Override
- public String toString() {
- return String.format("%s %s", this.getClass().getSimpleName(), super.toString());
- }
-}
-```
-
-Next, we present a runnable `Worker` class that the thread pool will utilize to handle all the potato peeling and coffee making.
-
-```java
-
-@Slf4j
-public class Worker implements Runnable {
-
- private final Task task;
-
- public Worker(final Task task) {
- this.task = task;
- }
-
- @Override
- public void run() {
- LOGGER.info("{} processing {}", Thread.currentThread().getName(), task.toString());
- try {
- Thread.sleep(task.getTimeMs());
- } catch (InterruptedException e) {
- LOGGER.error("Error occurred: ", e);
- }
- }
-}
-```
-
-Now, we are ready to show the full example in action.
-
-```java
-LOGGER.info("Program started");
-
-// Create a list of tasks to be executed
-var tasks = List.of(
- new PotatoPeelingTask(3),
- new PotatoPeelingTask(6),
- new CoffeeMakingTask(2),
- new CoffeeMakingTask(6),
- new PotatoPeelingTask(4),
- new CoffeeMakingTask(2),
- new PotatoPeelingTask(4),
- new CoffeeMakingTask(9),
- new PotatoPeelingTask(3),
- new CoffeeMakingTask(2),
- new PotatoPeelingTask(4),
- new CoffeeMakingTask(2),
- new CoffeeMakingTask(7),
- new PotatoPeelingTask(4),
- new PotatoPeelingTask(5));
-
-// Creates a thread pool that reuses a fixed number of threads operating off a shared
-// unbounded queue. At any point, at most nThreads threads will be active processing
-// tasks. If additional tasks are submitted when all threads are active, they will wait
-// in the queue until a thread is available.
-var executor = Executors.newFixedThreadPool(3);
-
-// Allocate new worker for each task
-// The worker is executed when a thread becomes
-// available in the thread pool
-tasks.stream().map(Worker::new).forEach(executor::execute);
-
-// All tasks were executed, now shutdown
-executor.shutdown();
-while (!executor.isTerminated()) {
- Thread.yield();
-}
-LOGGER.info("Program finished");
-```
-
-Running the example produces the following output:
-
-```
-13:47:07.244 [main] INFO com.iluwatar.threadpool.App -- Program started
-13:47:07.258 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing CoffeeMakingTask id=3 timeMs=200
-13:47:07.258 [pool-1-thread-2] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-2 processing PotatoPeelingTask id=2 timeMs=1200
-13:47:07.258 [pool-1-thread-1] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-1 processing PotatoPeelingTask id=1 timeMs=600
-13:47:07.464 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing CoffeeMakingTask id=4 timeMs=600
-13:47:07.864 [pool-1-thread-1] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-1 processing PotatoPeelingTask id=5 timeMs=800
-13:47:08.066 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing CoffeeMakingTask id=6 timeMs=200
-13:47:08.271 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing PotatoPeelingTask id=7 timeMs=800
-13:47:08.464 [pool-1-thread-2] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-2 processing CoffeeMakingTask id=8 timeMs=900
-13:47:08.668 [pool-1-thread-1] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-1 processing PotatoPeelingTask id=9 timeMs=600
-13:47:09.076 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing CoffeeMakingTask id=10 timeMs=200
-13:47:09.273 [pool-1-thread-1] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-1 processing PotatoPeelingTask id=11 timeMs=800
-13:47:09.277 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing CoffeeMakingTask id=12 timeMs=200
-13:47:09.367 [pool-1-thread-2] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-2 processing CoffeeMakingTask id=13 timeMs=700
-13:47:09.482 [pool-1-thread-3] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-3 processing PotatoPeelingTask id=14 timeMs=800
-13:47:10.072 [pool-1-thread-2] INFO com.iluwatar.threadpool.Worker -- pool-1-thread-2 processing PotatoPeelingTask id=15 timeMs=1000
-13:47:11.078 [main] INFO com.iluwatar.threadpool.App -- Program finished
-```
-
-## Class diagram
-
-
-
-## Applicability
-
-* When there are multiple tasks to be executed and creating a new thread for each task would be inefficient.
-* In scenarios where tasks are short-lived and the overhead of thread creation and destruction is significant.
-* When you need to control the number of concurrent threads to prevent resource exhaustion.
-
-## Known Uses
-
-* Java's `java.util.concurrent.ExecutorService` and `ThreadPoolExecutor`.
-* Web servers handling multiple client requests concurrently.
-* Background task execution in GUI applications to keep the user interface responsive.
-
-## Consequences
-
-Benefits:
-
-* Improved performance by reusing existing threads instead of creating new ones.
-* Better resource management by limiting the number of active threads.
-* Simplifies the management of concurrent task execution.
-
-Trade-offs:
-
-* Requires careful tuning of the thread pool size to balance resource utilization and performance.
-* Potential for thread starvation if the pool size is too small.
-* Complexity in handling task rejection and thread lifecycle management.
-
-## Related Patterns
-
-* [Promise](https://java-design-patterns.com/patterns/promise/): Used to represent the result of an asynchronous computation, often executed by a thread pool.
-* [Producer-Consumer](https://java-design-patterns.com/patterns/producer-consumer/): Threads in the pool consume tasks produced by another part of the application.
-* [Command](https://java-design-patterns.com/patterns/command/): Each task submitted to the thread pool can be treated as a command object.
-
-## Credits
-
-* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3w0pvKI)
-* [Effective Java](https://amzn.to/4cGk2Jz)
-* [Java Concurrency in Practice](https://amzn.to/4aRMruW)
diff --git a/thread-pool/etc/thread-pool.urm.puml b/thread-pool/etc/thread-pool.urm.puml
deleted file mode 100644
index 251033c81..000000000
--- a/thread-pool/etc/thread-pool.urm.puml
+++ /dev/null
@@ -1,37 +0,0 @@
-@startuml
-package com.iluwatar.threadpool {
- class App {
- - LOGGER : Logger {static}
- + App()
- + main(args : String[]) {static}
- }
- class CoffeeMakingTask {
- - TIME_PER_CUP : int {static}
- + CoffeeMakingTask(numCups : int)
- + toString() : String
- }
- class PotatoPeelingTask {
- - TIME_PER_POTATO : int {static}
- + PotatoPeelingTask(numPotatoes : int)
- + toString() : String
- }
- abstract class Task {
- - ID_GENERATOR : AtomicInteger {static}
- - id : int
- - timeMs : int
- + Task(timeMs : int)
- + getId() : int
- + getTimeMs() : int
- + toString() : String
- }
- class Worker {
- - LOGGER : Logger {static}
- - task : Task
- + Worker(task : Task)
- + run()
- }
-}
-Worker --> "-task" Task
-CoffeeMakingTask --|> Task
-PotatoPeelingTask --|> Task
-@enduml
\ No newline at end of file
diff --git a/thread-pool/etc/thread_pool_urm.png b/thread-pool/etc/thread_pool_urm.png
deleted file mode 100644
index 3d433824f..000000000
Binary files a/thread-pool/etc/thread_pool_urm.png and /dev/null differ
diff --git a/thread-pool/pom.xml b/thread-pool/pom.xml
deleted file mode 100644
index f58f771c0..000000000
--- a/thread-pool/pom.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
- 4.0.0
-
- com.iluwatar
- java-design-patterns
- 1.26.0-SNAPSHOT
-
- thread-pool
-
-
- org.junit.jupiter
- junit-jupiter-engine
- test
-
-
- org.mockito
- mockito-core
- test
-
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
-
-
-
- com.iluwatar.threadpool.App
-
-
-
-
-
-
-
-
-
diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/App.java b/thread-pool/src/main/java/com/iluwatar/threadpool/App.java
deleted file mode 100644
index a2c3f9e3a..000000000
--- a/thread-pool/src/main/java/com/iluwatar/threadpool/App.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * Thread Pool pattern is where a number of threads are created to perform a number of tasks, which
- * are usually organized in a queue. The results from the tasks being executed might also be placed
- * in a queue, or the tasks might return no result. Typically, there are many more tasks than
- * threads. As soon as a thread completes its task, it will request the next task from the queue
- * until all tasks have been completed. The thread can then terminate, or sleep until there are new
- * tasks available.
- *
- * In this example we create a list of tasks presenting work to be done. Each task is then
- * wrapped into a {@link Worker} object that implements {@link Runnable}. We create an {@link
- * ExecutorService} with fixed number of threads (Thread Pool) and use them to execute the {@link
- * Worker}s.
- */
-@Slf4j
-public class App {
-
- /**
- * Program entry point.
- *
- * @param args command line args
- */
- public static void main(String[] args) {
-
- LOGGER.info("Program started");
-
- // Create a list of tasks to be executed
- var tasks = List.of(
- new PotatoPeelingTask(3),
- new PotatoPeelingTask(6),
- new CoffeeMakingTask(2),
- new CoffeeMakingTask(6),
- new PotatoPeelingTask(4),
- new CoffeeMakingTask(2),
- new PotatoPeelingTask(4),
- new CoffeeMakingTask(9),
- new PotatoPeelingTask(3),
- new CoffeeMakingTask(2),
- new PotatoPeelingTask(4),
- new CoffeeMakingTask(2),
- new CoffeeMakingTask(7),
- new PotatoPeelingTask(4),
- new PotatoPeelingTask(5));
-
- // Creates a thread pool that reuses a fixed number of threads operating off a shared
- // unbounded queue. At any point, at most nThreads threads will be active processing
- // tasks. If additional tasks are submitted when all threads are active, they will wait
- // in the queue until a thread is available.
- var executor = Executors.newFixedThreadPool(3);
-
- // Allocate new worker for each task
- // The worker is executed when a thread becomes
- // available in the thread pool
- tasks.stream().map(Worker::new).forEach(executor::execute);
- // All tasks were executed, now shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- Thread.yield();
- }
- LOGGER.info("Program finished");
- }
-}
diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/CoffeeMakingTask.java b/thread-pool/src/main/java/com/iluwatar/threadpool/CoffeeMakingTask.java
deleted file mode 100644
index 423b4de3b..000000000
--- a/thread-pool/src/main/java/com/iluwatar/threadpool/CoffeeMakingTask.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-/**
- * CoffeeMakingTask is a concrete task.
- */
-public class CoffeeMakingTask extends Task {
-
- private static final int TIME_PER_CUP = 100;
-
- public CoffeeMakingTask(int numCups) {
- super(numCups * TIME_PER_CUP);
- }
-
- @Override
- public String toString() {
- return String.format("%s %s", this.getClass().getSimpleName(), super.toString());
- }
-}
diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/PotatoPeelingTask.java b/thread-pool/src/main/java/com/iluwatar/threadpool/PotatoPeelingTask.java
deleted file mode 100644
index 24e86ed83..000000000
--- a/thread-pool/src/main/java/com/iluwatar/threadpool/PotatoPeelingTask.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-/**
- * PotatoPeelingTask is a concrete task.
- */
-public class PotatoPeelingTask extends Task {
-
- private static final int TIME_PER_POTATO = 200;
-
- public PotatoPeelingTask(int numPotatoes) {
- super(numPotatoes * TIME_PER_POTATO);
- }
-
- @Override
- public String toString() {
- return String.format("%s %s", this.getClass().getSimpleName(), super.toString());
- }
-}
diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/Task.java b/thread-pool/src/main/java/com/iluwatar/threadpool/Task.java
deleted file mode 100644
index 0a1224d80..000000000
--- a/thread-pool/src/main/java/com/iluwatar/threadpool/Task.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import lombok.Getter;
-
-/**
- * Abstract base class for tasks.
- */
-public abstract class Task {
-
- private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
-
- @Getter
- private final int id;
- @Getter
- private final int timeMs;
-
- public Task(final int timeMs) {
- this.id = ID_GENERATOR.incrementAndGet();
- this.timeMs = timeMs;
- }
-
- @Override
- public String toString() {
- return String.format("id=%d timeMs=%d", id, timeMs);
- }
-}
diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java b/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java
deleted file mode 100644
index f70e36f2d..000000000
--- a/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * Worker implements {@link Runnable} and thus can be executed by {@link
- * java.util.concurrent.ExecutorService}.
- */
-@Slf4j
-public class Worker implements Runnable {
-
- private final Task task;
-
- public Worker(final Task task) {
- this.task = task;
- }
-
- @Override
- public void run() {
- LOGGER.info("{} processing {}", Thread.currentThread().getName(), task.toString());
- try {
- Thread.sleep(task.getTimeMs());
- } catch (InterruptedException e) {
- LOGGER.error("Error occurred: ", e);
- }
- }
-}
diff --git a/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java b/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java
deleted file mode 100644
index 3e91bbb7e..000000000
--- a/thread-pool/src/test/java/com/iluwatar/threadpool/AppTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-
-/**
- * Application test
- *
- */
-class AppTest {
-
- @Test
- void shouldExecuteWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
- }
-}
diff --git a/thread-pool/src/test/java/com/iluwatar/threadpool/CoffeeMakingTaskTest.java b/thread-pool/src/test/java/com/iluwatar/threadpool/CoffeeMakingTaskTest.java
deleted file mode 100644
index 5bc8c9177..000000000
--- a/thread-pool/src/test/java/com/iluwatar/threadpool/CoffeeMakingTaskTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-/**
- * CoffeeMakingTaskTest
- *
- */
-class CoffeeMakingTaskTest extends TaskTest {
-
- /**
- * Create a new test instance
- */
- public CoffeeMakingTaskTest() {
- super(CoffeeMakingTask::new, 100);
- }
-
-}
diff --git a/thread-pool/src/test/java/com/iluwatar/threadpool/PotatoPeelingTaskTest.java b/thread-pool/src/test/java/com/iluwatar/threadpool/PotatoPeelingTaskTest.java
deleted file mode 100644
index 7c05cdd3f..000000000
--- a/thread-pool/src/test/java/com/iluwatar/threadpool/PotatoPeelingTaskTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-/**
- * PotatoPeelingTaskTest
- *
- */
-class PotatoPeelingTaskTest extends TaskTest {
-
- /**
- * Create a new test instance
- */
- public PotatoPeelingTaskTest() {
- super(PotatoPeelingTask::new, 200);
- }
-
-}
\ No newline at end of file
diff --git a/thread-pool/src/test/java/com/iluwatar/threadpool/TaskTest.java b/thread-pool/src/test/java/com/iluwatar/threadpool/TaskTest.java
deleted file mode 100644
index cbb972436..000000000
--- a/thread-pool/src/test/java/com/iluwatar/threadpool/TaskTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-import static java.time.Duration.ofMillis;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTimeout;
-
-import java.util.ArrayList;
-import java.util.Objects;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.function.IntFunction;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for Tasks using a Thread Pool
- *
- * @param Type of Task
- */
-public abstract class TaskTest {
-
- /**
- * The number of tasks used during the concurrency test
- */
- private static final int TASK_COUNT = 128 * 1024;
-
- /**
- * The number of threads used during the concurrency test
- */
- private static final int THREAD_COUNT = 8;
-
- /**
- * The task factory, used to create new test items
- */
- private final IntFunction factory;
-
- /**
- * The expected time needed to run the task 1 single time, in milli seconds
- */
- private final int expectedExecutionTime;
-
- /**
- * Create a new test instance
- *
- * @param factory The task factory, used to create new test items
- * @param expectedExecutionTime The expected time needed to run the task 1 time, in milli seconds
- */
- public TaskTest(final IntFunction factory, final int expectedExecutionTime) {
- this.factory = factory;
- this.expectedExecutionTime = expectedExecutionTime;
- }
-
- /**
- * Verify if the generated id is unique for each task, even if the tasks are created in separate
- * threads
- */
- @Test
- void testIdGeneration() {
- assertTimeout(ofMillis(10000), () -> {
- final var service = Executors.newFixedThreadPool(THREAD_COUNT);
-
- final var tasks = IntStream.range(0, TASK_COUNT)
- .>mapToObj(i -> () -> factory.apply(1).getId())
- .collect(Collectors.toCollection(ArrayList::new));
-
- final var ids = service.invokeAll(tasks)
- .stream()
- .map(TaskTest::get)
- .filter(Objects::nonNull)
- .toList();
-
- service.shutdownNow();
-
- final var uniqueIdCount = ids.stream()
- .distinct()
- .count();
-
- assertEquals(TASK_COUNT, ids.size());
- assertEquals(TASK_COUNT, uniqueIdCount);
- });
- }
-
- /**
- * Verify if the time per execution of a task matches the actual time required to execute the task
- * a given number of times
- */
- @Test
- void testTimeMs() {
- for (var i = 0; i < 10; i++) {
- assertEquals(this.expectedExecutionTime * i, this.factory.apply(i).getTimeMs());
- }
- }
-
- /**
- * Verify if the task has some sort of {@link T#toString()}, different from 'null'
- */
- @Test
- void testToString() {
- assertNotNull(this.factory.apply(0).toString());
- }
-
- /**
- * Extract the result from a future or returns 'null' when an exception occurred
- *
- * @param future The future we want the result from
- * @param The result type
- * @return The result or 'null' when a checked exception occurred
- */
- private static O get(Future future) {
- try {
- return future.get();
- } catch (InterruptedException | ExecutionException e) {
- return null;
- }
- }
-
-}
diff --git a/thread-pool/src/test/java/com/iluwatar/threadpool/WorkerTest.java b/thread-pool/src/test/java/com/iluwatar/threadpool/WorkerTest.java
deleted file mode 100644
index c559f36ea..000000000
--- a/thread-pool/src/test/java/com/iluwatar/threadpool/WorkerTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.threadpool;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.junit.jupiter.api.Test;
-
-/**
- * WorkerTest
- *
- */
-class WorkerTest {
-
- /**
- * Verify if a worker does the actual job
- */
- @Test
- void testRun() {
- final var task = mock(Task.class);
- final var worker = new Worker(task);
- verifyNoMoreInteractions(task);
-
- worker.run();
- verify(task).getTimeMs();
- verifyNoMoreInteractions(task);
- }
-
-}
\ No newline at end of file