From 34c9c1eae66f1afea94ac976b974504d0529201e Mon Sep 17 00:00:00 2001 From: Aroooba Date: Fri, 14 Jul 2023 18:49:32 +0900 Subject: [PATCH] Move the blocking log operation to executor thread --- .../java/com/codingchili/core/logging/LogMessage.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/main/java/com/codingchili/core/logging/LogMessage.java b/core/main/java/com/codingchili/core/logging/LogMessage.java index 1b49860d..a69ac3f1 100644 --- a/core/main/java/com/codingchili/core/logging/LogMessage.java +++ b/core/main/java/com/codingchili/core/logging/LogMessage.java @@ -2,6 +2,9 @@ import io.vertx.core.json.JsonObject; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import static com.codingchili.core.configuration.CoreStrings.*; /** @@ -10,6 +13,7 @@ public class LogMessage { private Logger logger; private JsonObject event; + private final ExecutorService executor = Executors.newSingleThreadExecutor(); /** * Creates a new logging message. Constructor typically invoked indirectly @@ -50,7 +54,9 @@ public LogMessage put(String key, Object value) { * @return the logger that was used to send the message. */ public Logger send() { - logger.log(event); + executor.execute(() -> { + logger.log(event); + }); return logger; }