From 270f0d89ec30d041f5e8224ffbb9fe6459d7e8f6 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:52:21 +0700 Subject: [PATCH] is writing --- .../chomens_bot/util/PersistentDataUtilities.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java index 2fdcc37..44a47c1 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/PersistentDataUtilities.java @@ -14,6 +14,8 @@ public class PersistentDataUtilities { public static JsonObject jsonObject = new JsonObject(); + private static boolean isWriting = false; + static { init(); } @@ -40,6 +42,10 @@ public class PersistentDataUtilities { public static synchronized void write () { try { + if (isWriting) return; + + isWriting = true; + writer.close(); // ? how do i clear the file contents without making a completely new FileWriter @@ -48,6 +54,8 @@ public class PersistentDataUtilities { writer.write(jsonObject.toString()); writer.flush(); + + isWriting = false; } catch (IOException | ConcurrentModificationException e) { e.printStackTrace(); }