From f9c4b491ad8896cc7394521b6253c3e72d36ad76 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Fri, 2 Feb 2024 09:38:20 +0000 Subject: [PATCH] Change soft stop so that the index worker thread can exit - periodically poll from priority queue instead of take, giving the thread an opportunity to exit after DICOM storage was stopped --- .../main/java/pt/ua/dicoogle/server/DicomStorage.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 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 adb5221c6..7b9eb65c3 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java @@ -379,11 +379,15 @@ class IndexerQueueWorker implements Runnable { public void run() { while (true) { try { - // Fetch an element by the queue taking into account the priorities. if (workerShouldExit && queue.isEmpty()) { break; } - ImageElement element = queue.take(); + // Fetch an element from the priority queue + // with a timeout so that the thread can exit + ImageElement element = queue.poll(3, TimeUnit.SECONDS); + if (element == null) { + continue; + } URI exam = element.getUri(); if (ASYNC_INDEX) PluginController.getInstance().index(exam); @@ -395,7 +399,7 @@ public void run() { LOG.error("Unexpected error in indexer queue worker", ex); } } - LOG.debug("Indexer queue worker exiting by request"); + LOG.info("DICOM storage finished processing files"); } } @@ -422,5 +426,6 @@ public void start() throws IOException { public void stop() { device.stopListening(); workerShouldExit = true; + LOG.debug("Indexer queue worker will exit"); } }