Join all threads before end of main

Some calls from separate threads may throw exceptions once the main()
method has returned.
packet_merger
Romain Vimont 1 year ago
parent 730eb1086a
commit 400a1c69b1

@ -100,11 +100,17 @@ public class Controller {
public void stop() {
if (thread != null) {
thread.interrupt();
thread = null;
}
sender.stop();
}
public void join() throws InterruptedException {
if (thread != null) {
thread.join();
}
sender.join();
}
public DeviceMessageSender getSender() {
return sender;
}

@ -66,7 +66,12 @@ public final class DeviceMessageSender {
public void stop() {
if (thread != null) {
thread.interrupt();
thread = null;
}
}
public void join() throws InterruptedException {
if (thread != null) {
thread.join();
}
}
}

@ -117,6 +117,15 @@ public final class Server {
if (controller != null) {
controller.stop();
}
try {
initThread.join();
if (controller != null) {
controller.join();
}
} catch (InterruptedException e) {
// ignore
}
}
}
}

Loading…
Cancel
Save