From 5a5b9c18a837359af8c935ea8f6d5d6cb7600f27 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 5 Jul 2023 19:32:44 +0700 Subject: [PATCH] OMG fix!?!??! --- .../util/PersistentDataUtilities.java | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) 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 8d94b51..d674c32 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 @@ -40,6 +40,7 @@ public class PersistentDataUtilities { writer = new FileWriter(file, false); + // i already use ExecutorService so is a queue optional? Main.executor.scheduleAtFixedRate(() -> { if (queue.isEmpty()) return; @@ -75,38 +76,48 @@ public class PersistentDataUtilities { } } - public static void put (String property, JsonElement value) { - if (jsonObject.has(property)) jsonObject.remove(property); - jsonObject.add(property, value); - - queue.add(jsonObject.toString()); + public static synchronized void put (String property, JsonElement value) { + Main.executorService.submit(() -> { + if (jsonObject.has(property)) jsonObject.remove(property); + jsonObject.add(property, value); + + queue.add(jsonObject.toString()); + }); } - public static void put (String property, String value) { - if (jsonObject.has(property)) jsonObject.remove(property); - jsonObject.addProperty(property, value); + public static synchronized void put (String property, String value) { + Main.executorService.submit(() -> { + if (jsonObject.has(property)) jsonObject.remove(property); + jsonObject.addProperty(property, value); - queue.add(jsonObject.toString()); + queue.add(jsonObject.toString()); + }); } - public static void put (String property, boolean value) { - if (jsonObject.has(property)) jsonObject.remove(property); - jsonObject.addProperty(property, value); + public static synchronized void put (String property, boolean value) { + Main.executorService.submit(() -> { + if (jsonObject.has(property)) jsonObject.remove(property); + jsonObject.addProperty(property, value); - queue.add(jsonObject.toString()); + queue.add(jsonObject.toString()); + }); } - public static void put (String property, int value) { - if (jsonObject.has(property)) jsonObject.remove(property); - jsonObject.addProperty(property, value); + public static synchronized void put (String property, int value) { + Main.executorService.submit(() -> { + if (jsonObject.has(property)) jsonObject.remove(property); + jsonObject.addProperty(property, value); - queue.add(jsonObject.toString()); + queue.add(jsonObject.toString()); + }); } - public static void put (String property, char value) { - if (jsonObject.has(property)) jsonObject.remove(property); - jsonObject.addProperty(property, value); + public static synchronized void put (String property, char value) { + Main.executorService.submit(() -> { + if (jsonObject.has(property)) jsonObject.remove(property); + jsonObject.addProperty(property, value); - queue.add(jsonObject.toString()); + queue.add(jsonObject.toString()); + }); } }