From 8586aeefcd433f3bf88cfb78fafa2c5ecad2be07 Mon Sep 17 00:00:00 2001 From: Govindas Date: Thu, 8 Dec 2022 21:33:09 +0200 Subject: [PATCH] Re-add thread-pool-size config option, fixes #19 --- pom.xml | 2 +- src/main/java/com/btk5h/skriptdb/SkriptDB.java | 4 ++++ .../java/com/btk5h/skriptdb/skript/EffExecuteStatement.java | 3 +-- src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java | 2 +- src/main/resources/plugin.yml | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 6befcd0..07ec963 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.btk5h skript-db - 1.3.8 + 1.3.9 jar diff --git a/src/main/java/com/btk5h/skriptdb/SkriptDB.java b/src/main/java/com/btk5h/skriptdb/SkriptDB.java index 77115d7..4430ed4 100644 --- a/src/main/java/com/btk5h/skriptdb/SkriptDB.java +++ b/src/main/java/com/btk5h/skriptdb/SkriptDB.java @@ -73,6 +73,10 @@ public final class SkriptDB extends JavaPlugin { } try { if (out == null) return; + + out.write("# How many connections can be awaited for simultaneously, may be useful to increase if SQL database is hosted on a separate machine to account for ping.\n"); + out.write("# If it is hosted within the same machine, set it to the count of cores your processor has or the count of threads your processor can process at once.\n"); + out.write("thread-pool-size: " + (Runtime.getRuntime().availableProcessors() + 2) + "\n"); out.write("# Only change this if you wish to use a different driver than Java's default, like MariaDB driver.\n"); out.write("# If you use MariaDB, its driver is shaded together with skript-db, so you can just specify:" + "\"org.mariadb.jdbc.Driver\"" + ".\n"); out.write("sql-driver-class-name: " + "\"default\"" + "\n"); diff --git a/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java b/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java index 42cad0e..6a74670 100644 --- a/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java +++ b/src/main/java/com/btk5h/skriptdb/skript/EffExecuteStatement.java @@ -44,8 +44,7 @@ import java.util.concurrent.Executors; * @since 0.1.0 */ public class EffExecuteStatement extends Effect { - private static final ExecutorService threadPool = - Executors.newCachedThreadPool(); + private static final ExecutorService threadPool = Executors.newFixedThreadPool(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10)); static String lastError; static { diff --git a/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java b/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java index dd54e8a..1834382 100644 --- a/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java +++ b/src/main/java/com/btk5h/skriptdb/skript/ExprDataSource.java @@ -55,7 +55,7 @@ public class ExprDataSource extends SimpleExpression { } HikariDataSource ds = new HikariDataSource(); - + ds.setMaximumPoolSize(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 10)); //allow specifying of own sql driver class name if (!SkriptDB.getInstance().getConfig().getString("sql-driver-class-name", "default").equals("default")) { ds.setDriverClassName(SkriptDB.getInstance().getConfig().getString("sql-driver-class-name")); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cc56b99..045ac98 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: skript-db -version: 1.3.5 +version: 1.3.9 main: com.btk5h.skriptdb.SkriptDB depend: [Skript] authors: [btk5h, FranKusmiruk, Govindas, TPGamesNL]