From dded8cf08098c1e6db7b1cc4fbf2041386a4890a Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 24 Oct 2021 20:18:15 -0600 Subject: [PATCH 1/3] Include full exception when WatchQueueReader thread dies See #2537 Signed-off-by: Cody Cutrer --- .../org/openhab/core/service/WatchQueueReader.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java index 5614d5c1d2e..6986c28f714 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java @@ -202,8 +202,8 @@ public synchronized void stopWatchService(AbstractWatchService service) { @Override public void run() { - try { - for (;;) { + for (;;) { + try { WatchKey key; try { key = watchService.take(); @@ -272,11 +272,9 @@ public void run() { } key.reset(); + } catch (Exception exc) { + logger.error("Exception caught in WatchQueueReader: ", exc); } - } catch (Exception exc) { - logger.debug("ClosedWatchServiceException caught! {}. \n{} Stopping ", exc.getLocalizedMessage(), - Thread.currentThread().getName()); - return; } } From f0d1d93f5e97bc86b594859ad23a4506fb11317b Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 17 Jan 2022 17:00:19 -0700 Subject: [PATCH 2/3] handle thread interruptings in WatchQueueReader better --- .../org/openhab/core/service/WatchQueueReader.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java index f8386ff8e71..a304d5aed1e 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java @@ -203,15 +203,10 @@ public synchronized void stopWatchService(AbstractWatchService service) { @Override public void run() { - for (;;) { + while (!Thread.currentThread().isInterrupted()) { try { WatchKey key; - try { - key = watchService.take(); - } catch (InterruptedException exc) { - logger.info("Caught InterruptedException: {}", exc.getLocalizedMessage()); - return; - } + key = watchService.take(); for (WatchEvent event : key.pollEvents()) { WatchEvent.Kind kind = event.kind(); @@ -273,6 +268,9 @@ public void run() { } key.reset(); + } catch (InterruptedException exc) { + logger.debug("WatchQueueReader interrupted; thread exiting: {}", exc.getLocalizedMessage()); + return; } catch (Exception exc) { logger.error("Exception caught in WatchQueueReader: ", exc); } From 3d3e4fc543e9e80232d54f980db990e298c5b13d Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Tue, 18 Jan 2022 13:45:49 +0100 Subject: [PATCH 3/3] Tune logging Signed-off-by: Wouter Born --- .../main/java/org/openhab/core/service/WatchQueueReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java index a304d5aed1e..bde432db685 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/WatchQueueReader.java @@ -272,7 +272,7 @@ public void run() { logger.debug("WatchQueueReader interrupted; thread exiting: {}", exc.getLocalizedMessage()); return; } catch (Exception exc) { - logger.error("Exception caught in WatchQueueReader: ", exc); + logger.debug("Exception caught in WatchQueueReader", exc); } } }