Make thread pool configurable

This commit is contained in:
Govindas 2020-05-18 15:34:43 +03:00
parent b435696385
commit 8b5121d5fb
4 changed files with 42 additions and 5 deletions

View File

@ -1,5 +1,5 @@
group 'com.btk5h.skript-db'
version '0.1.1'
version '1.1.0'
buildscript {
repositories {
@ -53,4 +53,4 @@ task fatJar(type: Jar) {
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
}

View File

@ -25,9 +25,11 @@
package com.btk5h.skriptdb;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import javax.sql.rowset.RowSetFactory;
@ -49,6 +51,7 @@ public final class SkriptDB extends JavaPlugin {
private static SkriptAddon addonInstance;
private static RowSetFactory rowSetFactory;
protected FileConfiguration config;
public SkriptDB() {
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
public void onEnable() {
try {
@ -69,6 +100,11 @@ public final class SkriptDB extends JavaPlugin {
} catch (IOException e) {
e.printStackTrace();
}
try {
setupConfig();
} catch (IOException e) {
e.printStackTrace();
}
}
public static SkriptAddon getAddonInstance() {

View File

@ -51,7 +51,7 @@ public class EffExecuteStatement extends Delay {
static String lastError;
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<HikariDataSource> dataSource;

View File

@ -1,4 +1,5 @@
name: skript-db
version: 0.1.1
version: 1.1.0
main: com.btk5h.skriptdb.SkriptDB
depend: [Skript]
authors: [btk5h, FranKusmiruk, Govindas]