Skip to content

Commit

Permalink
Unused imports cleanup (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored Sep 16, 2024
1 parent 0ac103c commit 8c7f502
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/pivovarit/collectors/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void shouldNotConsumeOnEmpty() {
@Test
void shouldRestoreInterrupt() {
Thread executorThread = new Thread(() -> {
Spliterator<Integer> spliterator = new CompletionOrderSpliterator<>(Arrays.asList(new CompletableFuture<>()));
Spliterator<Integer> spliterator = new CompletionOrderSpliterator<>(List.of(new CompletableFuture<>()));
try {
spliterator.tryAdvance(i -> {});
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Stream<DynamicTest> 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))));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Stream<DynamicTest> 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());
Expand Down

0 comments on commit 8c7f502

Please sign in to comment.