[avmfritz] Properly interrupt monitor thread upon dispose (#9201)

* Properly interrupt monitor thread upon dispose

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer 2020-12-03 17:19:10 +01:00 committed by GitHub
parent 72b0c1473c
commit a736e64402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View 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,12 +124,14 @@ public class CallMonitor {
handler.setStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
while (!interrupted) {
try {
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) {
logger.debug("Lost connection to Fritzbox because of an interrupt.");
@ -136,8 +142,9 @@ public class CallMonitor {
break;
} finally {
try {
sleep(1000L);
sleep(500L);
} catch (InterruptedException e) {
interrupted = true;
}
}
}