From d6f5314b932f680489d159f5c9d2deb592a2049a Mon Sep 17 00:00:00 2001
From: ChomeNS <95471003+ChomeNS@users.noreply.github.com>
Date: Tue, 10 Oct 2023 14:28:30 +0700
Subject: [PATCH] fix concurrentfardexception in uh persistent data it's a
really simple fix but i didn't know about executorservices and stuff much
back then lol
---
.idea/jarRepositories.xml | 5 +++++
.../util/PersistentDataUtilities.java | 21 +++++++++----------
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index bc7b26a..1c3026b 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -46,5 +46,10 @@
+
+
+
+
+
\ No newline at end of file
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 2d606bb..4fe5cc3 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
@@ -32,7 +32,6 @@ public class PersistentDataUtilities {
init();
future = Main.executor.scheduleAtFixedRate(() -> {
- // TODO: thread-safe
try {
if (queue.isEmpty()) return;
@@ -91,23 +90,23 @@ public class PersistentDataUtilities {
} catch (IOException ignored) {}
}
- public static synchronized void put (String property, JsonElement value) {
- queue.put(property, value);
+ public static void put (String property, JsonElement value) {
+ Main.executorService.submit(() -> queue.put(property, value));
}
- public static synchronized void put (String property, String value) {
- queue.put(property, new JsonPrimitive(value));
+ public static void put (String property, String value) {
+ Main.executorService.submit(() -> queue.put(property, new JsonPrimitive(value)));
}
- public static synchronized void put (String property, boolean value) {
- queue.put(property, new JsonPrimitive(value));
+ public static void put (String property, boolean value) {
+ Main.executorService.submit(() -> queue.put(property, new JsonPrimitive(value)));
}
- public static synchronized void put (String property, int value) {
- queue.put(property, new JsonPrimitive(value));
+ public static void put (String property, int value) {
+ Main.executorService.submit(() -> queue.put(property, new JsonPrimitive(value)));
}
- public static synchronized void put (String property, char value) {
- queue.put(property, new JsonPrimitive(value));
+ public static void put (String property, char value) {
+ Main.executorService.submit(() -> queue.put(property, new JsonPrimitive(value)));
}
}