Skip to content

Commit

Permalink
Change soft stop so that the index worker thread can exit
Browse files Browse the repository at this point in the history
- periodically poll from priority queue
  instead of take,
  giving the thread an opportunity to exit
  after DICOM storage was stopped
  • Loading branch information
Enet4 committed Feb 2, 2024
1 parent 30f73de commit f9c4b49
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
}
}

Expand All @@ -422,5 +426,6 @@ public void start() throws IOException {
public void stop() {
device.stopListening();
workerShouldExit = true;
LOG.debug("Indexer queue worker will exit");
}
}

0 comments on commit f9c4b49

Please sign in to comment.