mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Fixing a race condition in socket server
- This caused the mocked test cases to sometimes hang. - Was particularly noticeable when running with code coverage.
This commit is contained in:
parent
a82a850a50
commit
ce6f04bdc7
@ -10,6 +10,8 @@ public abstract class SocketServer implements Runnable {
|
||||
private final int port;
|
||||
private ServerSocket socket;
|
||||
private Thread thread;
|
||||
|
||||
private boolean isStarted = false;
|
||||
private final Object lockObject = new Object();
|
||||
|
||||
protected SocketServer(int port) {
|
||||
@ -21,7 +23,9 @@ public abstract class SocketServer implements Runnable {
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
synchronized (lockObject) {
|
||||
lockObject.wait();
|
||||
if (!isStarted) {
|
||||
lockObject.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +41,7 @@ public abstract class SocketServer implements Runnable {
|
||||
|
||||
synchronized (lockObject) {
|
||||
lockObject.notify();
|
||||
isStarted = true;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
Loading…
Reference in New Issue
Block a user