diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java index 6147e36a..02684a1d 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Controller.java +++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java @@ -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; } diff --git a/server/src/main/java/com/genymobile/scrcpy/DeviceMessageSender.java b/server/src/main/java/com/genymobile/scrcpy/DeviceMessageSender.java index 7ec4ab41..b0e2a388 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DeviceMessageSender.java +++ b/server/src/main/java/com/genymobile/scrcpy/DeviceMessageSender.java @@ -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(); } } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 81c3e813..ac5f0293 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -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 + } } } }