From b3e520a2c3cb1293d2de8a4718c0c88904696798 Mon Sep 17 00:00:00 2001 From: Seraina Date: Tue, 17 May 2022 16:50:47 +0200 Subject: [PATCH] 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 --- .../gui/lounge/LobbyDisplayHandler.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyDisplayHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyDisplayHandler.java index 36fc4e2..24e2dfe 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyDisplayHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/lounge/LobbyDisplayHandler.java @@ -11,11 +11,20 @@ public class LobbyDisplayHandler { private static HashSet lobbies = new HashSet<>(); + private static boolean threadRunning = false; public static HashSet 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(); }