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 final int port;
|
||||||
private ServerSocket socket;
|
private ServerSocket socket;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
|
private boolean isStarted = false;
|
||||||
private final Object lockObject = new Object();
|
private final Object lockObject = new Object();
|
||||||
|
|
||||||
protected SocketServer(int port) {
|
protected SocketServer(int port) {
|
||||||
@ -21,7 +23,9 @@ public abstract class SocketServer implements Runnable {
|
|||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.start();
|
thread.start();
|
||||||
synchronized (lockObject) {
|
synchronized (lockObject) {
|
||||||
lockObject.wait();
|
if (!isStarted) {
|
||||||
|
lockObject.wait();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +41,7 @@ public abstract class SocketServer implements Runnable {
|
|||||||
|
|
||||||
synchronized (lockObject) {
|
synchronized (lockObject) {
|
||||||
lockObject.notify();
|
lockObject.notify();
|
||||||
|
isStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user