From 8c7f502c407440195d54205ef0b678983d24438b Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 16 Sep 2024 20:40:06 +0200 Subject: [PATCH] Unused imports cleanup (#951) --- LICENSE.md | 2 +- README.md | 2 +- .../com/pivovarit/collectors/Dispatcher.java | 19 ++++++++----------- .../CompletionOrderSpliteratorTest.java | 2 +- .../collectors/FutureCollectorsTest.java | 1 - .../collectors/test/BasicProcessingTest.java | 2 +- .../collectors/test/BatchingTest.java | 2 +- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index cee93f0d..b12b47ee 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [2020] [Grzegorz Piwowarek] + Copyright [2024] [Grzegorz Piwowarek] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 8713b0df..ce6abe31 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ Stream API is a great tool for collection processing, especially if you need to **However, Parallel Streams execute tasks on a shared `ForkJoinPool` instance**. -Unfortunately, it's not the best choice for running blocking operations even when using `ManagedBlocker` - [as explained here by Tagir Valeev](https://stackoverflow.com/a/37518272/2229438)) - this could easily lead to the saturation of the common pool, and to a performance degradation of everything that uses it. +Unfortunately, it's not the best choice for running blocking operations even when using `ManagedBlocker` - [as explained here by Tagir Valeev](https://stackoverflow.com/a/37518272/2229438) - this could easily lead to the saturation of the common pool, and to a performance degradation of everything that uses it. For example: diff --git a/src/main/java/com/pivovarit/collectors/Dispatcher.java b/src/main/java/com/pivovarit/collectors/Dispatcher.java index 3bb2b1a8..910a9cb2 100644 --- a/src/main/java/com/pivovarit/collectors/Dispatcher.java +++ b/src/main/java/com/pivovarit/collectors/Dispatcher.java @@ -9,7 +9,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.Semaphore; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.function.Supplier; @@ -85,17 +84,15 @@ void start() { } Runnable task; if ((task = workingQueue.take()) != POISON_PILL) { - retry(() -> { - executor.execute(() -> { - try { - task.run(); - } finally { - if (limiter != null) { - limiter.release(); - } + retry(() -> executor.execute(() -> { + try { + task.run(); + } finally { + if (limiter != null) { + limiter.release(); } - }); - }); + } + })); } else { break; } diff --git a/src/test/java/com/pivovarit/collectors/CompletionOrderSpliteratorTest.java b/src/test/java/com/pivovarit/collectors/CompletionOrderSpliteratorTest.java index 0dd4ea93..3457515e 100644 --- a/src/test/java/com/pivovarit/collectors/CompletionOrderSpliteratorTest.java +++ b/src/test/java/com/pivovarit/collectors/CompletionOrderSpliteratorTest.java @@ -92,7 +92,7 @@ void shouldNotConsumeOnEmpty() { @Test void shouldRestoreInterrupt() { Thread executorThread = new Thread(() -> { - Spliterator spliterator = new CompletionOrderSpliterator<>(Arrays.asList(new CompletableFuture<>())); + Spliterator spliterator = new CompletionOrderSpliterator<>(List.of(new CompletableFuture<>())); try { spliterator.tryAdvance(i -> {}); } catch (Exception e) { diff --git a/src/test/java/com/pivovarit/collectors/FutureCollectorsTest.java b/src/test/java/com/pivovarit/collectors/FutureCollectorsTest.java index b758f597..d541a77a 100644 --- a/src/test/java/com/pivovarit/collectors/FutureCollectorsTest.java +++ b/src/test/java/com/pivovarit/collectors/FutureCollectorsTest.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.IntStream; diff --git a/src/test/java/com/pivovarit/collectors/test/BasicProcessingTest.java b/src/test/java/com/pivovarit/collectors/test/BasicProcessingTest.java index fe579ef5..29aa4c62 100644 --- a/src/test/java/com/pivovarit/collectors/test/BasicProcessingTest.java +++ b/src/test/java/com/pivovarit/collectors/test/BasicProcessingTest.java @@ -57,7 +57,7 @@ Stream shouldStartProcessingImmediately() { var counter = new AtomicInteger(); Thread.startVirtualThread(() -> { - Stream.iterate(0, i -> i + 1) + var ignored = Stream.iterate(0, i -> i + 1) .limit(100) .collect(c.factory().collector(i -> returnWithDelay(counter.incrementAndGet(), ofSeconds(1)))); }); diff --git a/src/test/java/com/pivovarit/collectors/test/BatchingTest.java b/src/test/java/com/pivovarit/collectors/test/BatchingTest.java index d06ca7c7..8d3283bd 100644 --- a/src/test/java/com/pivovarit/collectors/test/BatchingTest.java +++ b/src/test/java/com/pivovarit/collectors/test/BatchingTest.java @@ -31,7 +31,7 @@ Stream shouldProcessOnExactlyNThreads() { var threads = new ConcurrentSkipListSet<>(); var parallelism = 4; - Stream.generate(() -> 42) + var ignored = Stream.generate(() -> 42) .limit(100) .collect(c.factory().collector(i -> { threads.add(Thread.currentThread().getName());