]> git.basschouten.com Git - openhab-addons.git/commitdiff
[avmfritz] Properly interrupt monitor thread upon dispose (#9201)
authorKai Kreuzer <kai@openhab.org>
Thu, 3 Dec 2020 16:19:10 +0000 (17:19 +0100)
committerGitHub <noreply@github.com>
Thu, 3 Dec 2020 16:19:10 +0000 (17:19 +0100)
* Properly interrupt monitor thread upon dispose

Signed-off-by: Kai Kreuzer <kai@openhab.org>
bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/callmonitor/CallMonitor.java

index 55707339f188412bf484261e12f8891bf33a07d5..6905c9aa491094e94cc1607066f20822c0cc5242 100644 (file)
@@ -75,6 +75,10 @@ public class CallMonitor {
      */
     public void dispose() {
         reconnectJob.cancel(true);
+        CallMonitorThread monitorThread = this.monitorThread;
+        if (monitorThread != null) {
+            monitorThread.interrupt();
+        }
     }
 
     public class CallMonitorThread extends Thread {
@@ -120,11 +124,13 @@ public class CallMonitor {
                     handler.setStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
                     while (!interrupted) {
                         try {
-                            String line = reader.readLine();
-                            if (line != null) {
-                                logger.debug("Received raw call string from fbox: {}", line);
-                                CallEvent ce = new CallEvent(line);
-                                handleCallEvent(ce);
+                            if (reader.ready()) {
+                                String line = reader.readLine();
+                                if (line != null) {
+                                    logger.debug("Received raw call string from fbox: {}", line);
+                                    CallEvent ce = new CallEvent(line);
+                                    handleCallEvent(ce);
+                                }
                             }
                         } catch (IOException e) {
                             if (interrupted) {
@@ -136,8 +142,9 @@ public class CallMonitor {
                             break;
                         } finally {
                             try {
-                                sleep(1000L);
+                                sleep(500L);
                             } catch (InterruptedException e) {
+                                interrupted = true;
                             }
                         }
                     }