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