Make thread pool configurable
This commit is contained in:
parent
b435696385
commit
8b5121d5fb
@ -1,5 +1,5 @@
|
|||||||
group 'com.btk5h.skript-db'
|
group 'com.btk5h.skript-db'
|
||||||
version '0.1.1'
|
version '1.1.0'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -25,9 +25,11 @@
|
|||||||
|
|
||||||
package com.btk5h.skriptdb;
|
package com.btk5h.skriptdb;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import javax.sql.rowset.RowSetFactory;
|
import javax.sql.rowset.RowSetFactory;
|
||||||
@ -49,6 +51,7 @@ public final class SkriptDB extends JavaPlugin {
|
|||||||
private static SkriptAddon addonInstance;
|
private static SkriptAddon addonInstance;
|
||||||
|
|
||||||
private static RowSetFactory rowSetFactory;
|
private static RowSetFactory rowSetFactory;
|
||||||
|
protected FileConfiguration config;
|
||||||
|
|
||||||
public SkriptDB() {
|
public SkriptDB() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@ -58,6 +61,34 @@ public final class SkriptDB extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupConfig() throws IOException {
|
||||||
|
//don't check if it exists, because mkdir already does that
|
||||||
|
File file = new File("plugins/skript-db/config.yml");
|
||||||
|
if (file.getParentFile().mkdirs()) {
|
||||||
|
BufferedWriter out = null;
|
||||||
|
try {
|
||||||
|
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("plugins/skript-db/config.yml", false), StandardCharsets.UTF_8));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (out == null) return;
|
||||||
|
|
||||||
|
out.write("# How many connections can be awaited for simultaneously, may be useful to increase if mysql 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() + 1) + "\n");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
@ -69,6 +100,11 @@ public final class SkriptDB extends JavaPlugin {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
setupConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SkriptAddon getAddonInstance() {
|
public static SkriptAddon getAddonInstance() {
|
||||||
|
@ -51,7 +51,7 @@ public class EffExecuteStatement extends Delay {
|
|||||||
static String lastError;
|
static String lastError;
|
||||||
|
|
||||||
private static final ExecutorService threadPool =
|
private static final ExecutorService threadPool =
|
||||||
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
Executors.newFixedThreadPool(SkriptDB.getInstance().getConfig().getInt("thread-pool-size"));
|
||||||
|
|
||||||
private Expression<String> query;
|
private Expression<String> query;
|
||||||
private Expression<HikariDataSource> dataSource;
|
private Expression<HikariDataSource> dataSource;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
name: skript-db
|
name: skript-db
|
||||||
version: 0.1.1
|
version: 1.1.0
|
||||||
main: com.btk5h.skriptdb.SkriptDB
|
main: com.btk5h.skriptdb.SkriptDB
|
||||||
depend: [Skript]
|
depend: [Skript]
|
||||||
|
authors: [btk5h, FranKusmiruk, Govindas]
|
||||||
|
Loading…
Reference in New Issue
Block a user