From 30f73decbe0b18b3ebd6def9896c4efe7f34d96a Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Fri, 26 Jan 2024 17:16:45 +0000 Subject: [PATCH] Change DICOM storage stop behavior to soft stop - let the index queue worker thread finish processing all items in queue before exiting - do not interrupt ongoing indexing tasks --- .../main/java/pt/ua/dicoogle/server/DicomStorage.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java b/dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java index 467f8914b..adb5221c6 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java @@ -80,6 +80,10 @@ public class DicomStorage extends StorageService { private BlockingQueue queue = new PriorityBlockingQueue<>(); private NetworkApplicationEntity[] naeArr = null; private AtomicLong seqNum = new AtomicLong(0L); + /** + * Whether the index worker thread + * should exit once it finishes processing the queue. + */ private volatile boolean workerShouldExit = false; private static boolean ASYNC_INDEX = Boolean.valueOf(System.getProperty("dicoogle.index.async", "true")); @@ -373,9 +377,12 @@ class IndexerQueueWorker implements Runnable { @Override public void run() { - while (!workerShouldExit) { + while (true) { try { // Fetch an element by the queue taking into account the priorities. + if (workerShouldExit && queue.isEmpty()) { + break; + } ImageElement element = queue.take(); URI exam = element.getUri(); if (ASYNC_INDEX) @@ -415,6 +422,5 @@ public void start() throws IOException { public void stop() { device.stopListening(); workerShouldExit = true; - indexer.interrupt(); } }