diff options
| author | 2026-08-02 21:43:55 +0200 | |
|---|---|---|
| committer | 2026-08-02 21:43:55 +0200 | |
| commit | 991671a8bafc6f6200cfb42d3fed9c68445217a5 (patch) | |
| tree | 7f3ee378b23d3049654269fb5905a430f2153b18 /src | |
| parent | 23e83b23962dba0e87f3715b9240699f8b1a8c3b (diff) | |
Updated some comments and improved readability of code
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/com/it_jaros/jscanner/Scanner.java | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/main/java/com/it_jaros/jscanner/Scanner.java b/src/main/java/com/it_jaros/jscanner/Scanner.java index 86875ea..418bad2 100644 --- a/src/main/java/com/it_jaros/jscanner/Scanner.java +++ b/src/main/java/com/it_jaros/jscanner/Scanner.java @@ -134,14 +134,13 @@ public class Scanner implements AutoCloseable { try { threadCounter.inc(); while (!cancelled && queue.hasNext()) { + // get semaphore and remember if task got submitted + // so in case we fail to submit we release the semaphore activeWorkers.acquire(); - - // remember if we submitted anything - // so we can release the semaphore - boolean submitted = false; + boolean isTaskSubmitted = false; try { - // just in case something changed while waiting - // for the semaphore + // just in case something + // changed while waiting if (cancelled) { break; } @@ -152,16 +151,14 @@ public class Scanner implements AutoCloseable { Callable<OUTPUT> task = taskFactory.apply(item); inPipeline.incrementAndGet(); try { - // here we are filling the completion service - // host <-> virtual thread completionService.submit(task); - submitted = true; + isTaskSubmitted = true; } catch (Throwable e) { inPipeline.decrementAndGet(); throw e; } } finally { - if (!submitted) { + if (!isTaskSubmitted) { activeWorkers.release(); } } @@ -228,7 +225,7 @@ public class Scanner implements AutoCloseable { } private ScanResult scanHostPorts() { - if (!disableOnlineCheck && !checkHostOnline(host)) { + if (!disableOnlineCheck && !checkHostOnline()) { // Unreachable host return ScanResult.empty(host); } @@ -262,11 +259,11 @@ public class Scanner implements AutoCloseable { return accumulator.build(); } - private boolean checkHostOnline(String host) { + private boolean checkHostOnline() { try { return InetAddress.getByName(host).isReachable(timeoutInMillis); } catch (IOException e) { - // something went wrong + // we ignore this error because it means that the host is probably not online } return false; |
