|
21 | 21 | import java.util.LinkedList; |
22 | 22 | import java.util.List; |
23 | 23 | import java.util.concurrent.*; |
| 24 | +import java.util.concurrent.atomic.AtomicInteger; |
24 | 25 | import org.apache.logging.log4j.LogManager; |
25 | 26 | import org.apache.logging.log4j.Logger; |
26 | 27 |
|
@@ -56,8 +57,8 @@ public class ThreadedScanJobExecutor< |
56 | 57 | // Used for waiting for Threads in the ThreadPoolExecutor |
57 | 58 | private final Semaphore semaphore; |
58 | 59 |
|
59 | | - private int probeCount; |
60 | | - private int finishedProbes = 0; |
| 60 | + private volatile int probeCount; |
| 61 | + private final AtomicInteger finishedProbes = new AtomicInteger(0); |
61 | 62 |
|
62 | 63 | /** |
63 | 64 | * Creates a new ThreadedScanJobExecutor with a custom thread pool. |
@@ -140,13 +141,13 @@ private void executeProbesTillNoneCanBeExecuted(ReportT report) throws Interrupt |
140 | 141 | List<Future<ScannerProbe<ReportT, StateT>>> finishedFutures = new ArrayList<>(); |
141 | 142 | for (Future<ScannerProbe<ReportT, StateT>> result : new ArrayList<>(futureResults)) { |
142 | 143 | if (result.isDone()) { |
143 | | - finishedProbes++; |
| 144 | + int currentFinishedProbes = finishedProbes.incrementAndGet(); |
144 | 145 | ScannerProbe<ReportT, StateT> probeResult = null; |
145 | 146 | try { |
146 | 147 | probeResult = result.get(); |
147 | 148 | LOGGER.info( |
148 | 149 | "[{}/{}] {} probe executed", |
149 | | - finishedProbes, |
| 150 | + currentFinishedProbes, |
150 | 151 | probeCount, |
151 | 152 | probeResult.getType().getName()); |
152 | 153 | } catch (ExecutionException e) { |
|
0 commit comments