From ddcbdbaec5d210d685ea1263179df6838737bee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Wed, 14 Oct 2026 21:07:27 +0200 Subject: [PATCH] fixed dropped database statements never completing their query --- .../spawn/core/database/Database.java | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/eu/mhsl/craftattack/spawn/core/database/Database.java b/core/src/main/java/eu/mhsl/craftattack/spawn/core/database/Database.java index 153ec94..c5ef7fb 100644 --- a/core/src/main/java/eu/mhsl/craftattack/spawn/core/database/Database.java +++ b/core/src/main/java/eu/mhsl/craftattack/spawn/core/database/Database.java @@ -9,6 +9,7 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -36,7 +37,7 @@ public class Database { 1, 1, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(1000), runnable -> new Thread(runnable, "Spawn-Database"), - (runnable, executor) -> Main.logger().warning("Database queue full, dropping statement") + new ThreadPoolExecutor.AbortPolicy() ); private @Nullable Connection connection; @@ -69,13 +70,19 @@ public class Database { */ public void execute(String description, SqlAction action) { if(!this.isAvailable()) return; - this.executor.execute(() -> { - try { - action.run(this.getConnection()); - } catch(SQLException e) { - this.handleError(description, e); - } - }); + try { + this.executor.execute(() -> { + try { + action.run(this.getConnection()); + } catch(SQLException e) { + this.handleError(description, e); + } catch(RuntimeException e) { + Main.logger().log(Level.WARNING, String.format("Database: %s failed", description), e); + } + }); + } catch(RejectedExecutionException e) { + Main.logger().warning("Database queue full, dropping statement"); + } } /** @@ -87,16 +94,21 @@ public class Database { future.completeExceptionally(new IllegalStateException("No database configured")); return future; } - this.executor.execute(() -> { - try { - future.complete(query.run(this.getConnection())); - } catch(SQLException e) { - this.closeConnection(); - future.completeExceptionally(e); - } catch(RuntimeException e) { - future.completeExceptionally(e); - } - }); + try { + this.executor.execute(() -> { + try { + future.complete(query.run(this.getConnection())); + } catch(SQLException e) { + this.closeConnection(); + future.completeExceptionally(e); + } catch(RuntimeException e) { + future.completeExceptionally(e); + } + }); + } catch(RejectedExecutionException e) { + Main.logger().warning("Database queue full, dropping statement"); + future.completeExceptionally(e); + } return future; }