diff options
| author | 2026-07-08 00:13:37 +0200 | |
|---|---|---|
| committer | 2026-07-09 09:59:29 +0200 | |
| commit | 8cc1e389d1ac9a2d92c8976767be8f3273336dc1 (patch) | |
| tree | bb1bdd9b404fbca10d9e8c1c42aec060e647235e | |
| parent | 755526e31e32c4447795c422461adbec91230f3a (diff) | |
Early exit through canceled check. Now shutdown is dramatically faster
| -rw-r--r-- | src/main/java/com/it_jaros/jscanner/Scanner.java | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/main/java/com/it_jaros/jscanner/Scanner.java b/src/main/java/com/it_jaros/jscanner/Scanner.java index 4910b9c..f656854 100644 --- a/src/main/java/com/it_jaros/jscanner/Scanner.java +++ b/src/main/java/com/it_jaros/jscanner/Scanner.java @@ -71,6 +71,7 @@ public class Scanner implements AutoCloseable { try { scan.getHostCounter().inc(); scan.getHostTotalCounter().inc(); + if (cancelled) return null; return scanHostPorts(host, scan); } finally { scan.getHostCounter().dec(); @@ -149,7 +150,7 @@ public class Scanner implements AutoCloseable { // consumer is the main thread // we run as long as the producer is running or as long as things are in pipeline to be processed // only exception is when cancelled is set - while ((state.running().get() || state.inPipeline().get() > 0) && !cancelled) { + while (!cancelled && (state.running().get() || state.inPipeline().get() > 0)) { try { Future<PortResult> portResultFuture = state.completionService().poll(10, TimeUnit.MILLISECONDS); if (portResultFuture == null) { @@ -213,7 +214,7 @@ public class Scanner implements AutoCloseable { executor.submit(() -> { try { threadCounter.inc(); - while (queue.hasNext() && !cancelled) { + while (!cancelled && queue.hasNext()) { activeWorkers.acquire(); // remember if we submitted anything |
