Changed some layouts, wasted a lot of time and made sure the LobbyDisplayHandler-Updater can only have one thread at a time that is writing to the same data

This commit is contained in:
Seraina 2022-05-17 16:50:47 +02:00
parent 3b5b2da60e
commit b3e520a2c3

View File

@ -11,11 +11,20 @@ public class LobbyDisplayHandler {
private static HashSet<LobbyModel> lobbies = new HashSet<>();
private static boolean threadRunning = false;
public static HashSet<LobbyModel> getLobbies() {
return lobbies;
}
public static void setThreadRunning(boolean threadRunning) {
LobbyDisplayHandler.threadRunning = threadRunning;
}
public static boolean isThreadRunning() {
return threadRunning;
}
/**
* searches lobbies for a lobby with a certain id
* @param id the int representing a Lobby id to be lookes for
@ -34,6 +43,14 @@ public class LobbyDisplayHandler {
new Thread(new Runnable() {
@Override
public void run() {
while(isThreadRunning()) {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
setThreadRunning(true);
try {
for (LobbyModel model : lobbies) {
model.setHasBeenVisited(false);
@ -58,8 +75,11 @@ public class LobbyDisplayHandler {
} catch (Exception e) {
e.printStackTrace();
LOGGER.info("empty list");
} finally {
setThreadRunning(false);
}
}
}).start();
}