Skip to content

Commit

Permalink
[avmfritz] Properly interrupt monitor thread upon dispose (openhab#9201)
Browse files Browse the repository at this point in the history
* Properly interrupt monitor thread upon dispose

Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and boehan committed Apr 12, 2021
1 parent b812950 commit 475260a
Showing 1 changed file with 13 additions and 6 deletions.
Expand Up @@ -75,6 +75,10 @@ public CallMonitor(String ip, BoxHandler handler, ScheduledExecutorService sched
*/
public void dispose() {
reconnectJob.cancel(true);
CallMonitorThread monitorThread = this.monitorThread;
if (monitorThread != null) {
monitorThread.interrupt();
}
}

public class CallMonitorThread extends Thread {
Expand Down Expand Up @@ -120,11 +124,13 @@ public void run() {
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) {
Expand All @@ -136,8 +142,9 @@ public void run() {
break;
} finally {
try {
sleep(1000L);
sleep(500L);
} catch (InterruptedException e) {
interrupted = true;
}
}
}
Expand Down

0 comments on commit 475260a

Please sign in to comment.