fixed dropped database statements never completing their query
This commit is contained in:
1 parent
7bd1e13660
commit
ddcbdbaec5
1 file changed
+13
-1
@@ -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;
|
||||
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,6 +94,7 @@ public class Database {
|
||||
future.completeExceptionally(new IllegalStateException("No database configured"));
|
||||
return future;
|
||||
}
|
||||
try {
|
||||
this.executor.execute(() -> {
|
||||
try {
|
||||
future.complete(query.run(this.getConnection()));
|
||||
@@ -97,6 +105,10 @@ public class Database {
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
} catch(RejectedExecutionException e) {
|
||||
Main.logger().warning("Database queue full, dropping statement");
|
||||
future.completeExceptionally(e);
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user