Force server exit at the end of main()

By default, the Java process exits when all non-daemon threads are
terminated.

The Android SDK might start some non-daemon threads internally,
preventing the scrcpy server to exit in some cases.

So force the process to exit explicitly.

PR #4213 <https://github.com/Genymobile/scrcpy/pull/4213>
camera.36
Romain Vimont 7 months ago
parent 23e116064d
commit 41ccb5883e

@ -170,7 +170,22 @@ public final class Server {
return thread;
}
public static void main(String... args) throws Exception {
public static void main(String... args) {
int status = 0;
try {
internalMain(args);
} catch (Throwable t) {
t.printStackTrace();
status = 1;
} finally {
// By default, the Java process exits when all non-daemon threads are terminated.
// The Android SDK might start some non-daemon threads internally, preventing the scrcpy server to exit.
// So force the process to exit explicitly.
System.exit(status);
}
}
private static void internalMain(String... args) throws Exception {
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
Ln.e("Exception on thread " + t, e);
});

Loading…
Cancel
Save