mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-05 07:39:23 +00:00
Join all threads before end of main
Some calls run from separate threads may throw exceptions when the main() method has returned.
This commit is contained in:
parent
6524e90c68
commit
4f986d4bbb
3 changed files with 22 additions and 2 deletions
|
@ -100,11 +100,17 @@ public class Controller {
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (thread != null) {
|
if (thread != null) {
|
||||||
thread.interrupt();
|
thread.interrupt();
|
||||||
thread = null;
|
|
||||||
}
|
}
|
||||||
sender.stop();
|
sender.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void join() throws InterruptedException {
|
||||||
|
if (thread != null) {
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
sender.join();
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceMessageSender getSender() {
|
public DeviceMessageSender getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,12 @@ public final class DeviceMessageSender {
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (thread != null) {
|
if (thread != null) {
|
||||||
thread.interrupt();
|
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) {
|
if (controller != null) {
|
||||||
controller.stop();
|
controller.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
initThread.join();
|
||||||
|
if (controller != null) {
|
||||||
|
controller.join();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue