|
38 | 38 | import java.util.concurrent.BlockingQueue; |
39 | 39 | import java.util.concurrent.CompletableFuture; |
40 | 40 | import java.util.concurrent.ExecutorService; |
| 41 | +import java.util.concurrent.TimeUnit; |
41 | 42 | import java.util.concurrent.atomic.AtomicInteger; |
42 | 43 | import java.util.concurrent.atomic.AtomicLong; |
43 | 44 | import java.util.stream.Collectors; |
@@ -178,7 +179,10 @@ private void tasksRunner( |
178 | 179 | progressTracker.endSubTask("create walks"); |
179 | 180 |
|
180 | 181 | try { |
181 | | - walks.put(tombstone); |
| 182 | + boolean finished = false; |
| 183 | + while (!finished && terminationFlag.running()) { |
| 184 | + finished = walks.offer(tombstone, 100, TimeUnit.MILLISECONDS); |
| 185 | + } |
182 | 186 | } catch (InterruptedException exception) { |
183 | 187 | Thread.currentThread().interrupt(); |
184 | 188 | } |
@@ -326,9 +330,13 @@ public void run() { |
326 | 330 | private boolean flushBuffer(int bufferLength) { |
327 | 331 | bufferLength = Math.min(bufferLength, this.buffer.length); |
328 | 332 |
|
329 | | - for (int i = 0; i < bufferLength && terminationFlag.running(); i++) { |
| 333 | + int i = 0; |
| 334 | + while (i < bufferLength && terminationFlag.running()) { |
330 | 335 | try { |
331 | | - walks.put(this.buffer[i]); |
| 336 | + // allow termination to occur if queue is full |
| 337 | + if (walks.offer(this.buffer[i], 100, TimeUnit.MILLISECONDS)) { |
| 338 | + i++; |
| 339 | + } |
332 | 340 | } catch (InterruptedException e) { |
333 | 341 | Thread.currentThread().interrupt(); |
334 | 342 | return false; |
|
0 commit comments