From 0bb4af1f0db9bec0590c7bdccb9fe8b99d15d795 Mon Sep 17 00:00:00 2001 From: Matthias Jaros Date: Sun, 5 Jul 2026 07:09:56 +0200 Subject: Improved shutdown logic that finally works properly Now if the user quits, then the main thread continues to collect all available results the producer and the host scan port threads close as soon as they check the flag and return whatever they have till now --- src/main/java/com/it_jaros/jscanner/App.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/main/java/com/it_jaros/jscanner/App.java') diff --git a/src/main/java/com/it_jaros/jscanner/App.java b/src/main/java/com/it_jaros/jscanner/App.java index 8fa3cca..700b3f0 100644 --- a/src/main/java/com/it_jaros/jscanner/App.java +++ b/src/main/java/com/it_jaros/jscanner/App.java @@ -1,17 +1,14 @@ package com.it_jaros.jscanner; -import java.time.Duration; import java.util.BitSet; import java.util.List; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class App { private static Thread shutdownHook; private static final CountDownLatch shutdownLatch = new CountDownLatch(1); - private static final int shutdownTimeoutInMillis = 5000; public static void main(String[] args) { try { @@ -113,10 +110,7 @@ public class App { private static void shutdown(Scanner scanner) { try { scanner.cancel(); - if (!scanner.awaitTermination(Duration.ofMillis(shutdownTimeoutInMillis))) { - scanner.cancelNow(); - } - shutdownLatch.await(shutdownTimeoutInMillis, TimeUnit.MILLISECONDS); + shutdownLatch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { -- cgit v1.3.1