Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[avmfritz] Properly interrupt monitor thread upon dispose #9201

Merged
merged 2 commits into from Dec 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
kaikreuzer marked this conversation as resolved.
Show resolved Hide resolved
}

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